通过python从Google Place API检索标记之间的可用文本

2024-09-30 10:41:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过从url检索JSON并通过BeautifulSoup运行来收集某些信息

from bs4 import BeautifulSoup as soup
from urllib.request import urlopen as uReq
import googlemaps

placeDetailsResult = 
urllib.request.urlopen('https://maps.googleapis.com/maps/api/place/details/
json? 
placeid=ChIJXSggtzAF1h0RXd_aMn0d16Q&cr=countryZA&lr=lang_en&key='+googleKey)
.read()
info = json.loads(placeDetailsResult.decode('utf-8'))
ghtml = info.content
gsoup = soup(ghtml, "lxml")
rawFormattedAddress = gsoup.find_all('span', attrs={'class': 
'Formatted_Address'})
print(rawFormattedAddress)

我得到:

ghtml = info.content AttributeError: 'dict' object has no attribute 'content'

我一直在编码和解码,试图解决一个又一个问题,有没有更简单的方法从谷歌api结果中检索标签信息?我在做什么可怕的事吗


Tags: fromimportinfoapi信息requestascontent

热门问题