相关疑难解决方法(0)

使用python中的bing或google API获取位置坐标

这是我的问题.我有一个示例文本文件,我通过爬行各种html页面来存储文本数据.本文包含有关各种事件及其时间和地点的信息.我想获取这些位置的坐标.我不知道如何在python中做到这一点.我使用nltk来识别此示例文本中的命名实体.这是代码:

import nltk

with open('sample.txt', 'r') as f:
    sample = f.read()

sentences = nltk.sent_tokenize(sample)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)

#print chunked_sentences
#print tokenized_sentences
#print tagged_sentences

def extract_entity_names(t):
    entity_names = []

    if hasattr(t, 'node') and t.node:
        if t.node == 'NE':
            entity_names.append(' '.join([child[0] for child in t]))
        else:
            for child in t:
                entity_names.extend(extract_entity_names(child))

    return entity_names

entity_names = []
for tree in chunked_sentences:
    # Print results per sentence
    # print …
Run Code Online (Sandbox Code Playgroud)

python google-maps nltk coordinates bing-maps

3
推荐指数
2
解决办法
6806
查看次数

通过检查 html 查找纬度和经度

有没有更简单的方法可以从此网址的html中查找坐标= https://www.sreality.cz/detail/prodej/byt/1+kk/praha-zizkov-krasova/151897164

我检查了该网站,但到目前为止似乎没有任何坐标。该网站正在使用mapy.cz

我尝试将地址转换为坐标,但坐标有时会关闭。

这是我尝试过的:

address = 'praha zizkov krasova'
url = 'https://nominatim.openstreetmap.org/search/' + urllib.parse.quote(address) +'?format=json'

response = requests.get(url).json()
print(response[0]["lat"])
print(response[0]["lon"])
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup web-scraping

0
推荐指数
1
解决办法
82
查看次数