特别是在google上获取详细的Python评论

2024-09-30 20:36:32 发布

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

我对这个模块和Python完全陌生,但我想在业余时间开始一些有趣的项目。 我有一个关于Python的GooglePlaces模块的具体问题——如何通过只知道位置ID来检索一个地方的评论

到目前为止我已经做了。。。在

from googleplaces import GooglePlaces, types, lang

google_places = GooglePlaces('API KEY')

query_result = google_places.get_place(place_id="ChIJB8wSOI11nkcRI3C2IODoBU0")

print(query_result) #<Place name="Starbucks", lat=48.14308250000001, lng=11.5782337>

print(query_result.get_details()) # Prints None

print(query_result.rating) # Prints the rating of 4.3

我在这里完全迷路了,因为我无法获取对象的详细信息。也许我遗漏了一些东西,但我会非常感谢通过我的问题的任何指导。在


Tags: 模块项目idgetgoogleplaceresultquery
1条回答
网友
1楼 · 发布于 2024-09-30 20:36:32

如果你完全迷路了,请阅读文档:)

来自https://github.com/slimkrazy/python-google-places的示例:

for place in query_result.places:
    # Returned places from a query are place summaries.

    # The following method has to make a further API call.
    place.get_details()
    # Referencing any of the attributes below, prior to making a call to
    # get_details() will raise a googleplaces.GooglePlacesAttributeError.
    print place.details # A dict matching the JSON response from Google.

现在看到代码的问题了吗?在

^{pr2}$

应该是

query_result.get_details() # Fetch details
print(query_result.details) # Prints details dict

关于结果,Google Docs声明:

reviews[] a JSON array of up to five reviews. If a language parameter was specified in the Place Details request, the Places Service will bias the results to prefer reviews written in that language. Each review consists of several components:

相关问题 更多 >