如何使用Beautiful Soup从python访问Google地图的类型(widget-panel-link)

问题描述 投票:0回答:1

Google Maps type of place tag

我试图在名称El Merendero下获得标签American Restaurant,并使用蟒蛇和美丽的汤来评论4.1但我无法进入。有关如何查找此谷歌地图类别的任何提示?

我得到的是这个文本,我猜有一些Javascript错误:

启用JavaScript以查看Google地图。

我的代码:

import requests
from bs4 import BeautifulSoup

Query = " Restaurant el merendero "

durl= "https://www.google.com/maps/search/?api=1&query=%s" % Query
page = requests.get(durl)
soup = BeautifulSoup(page.content, 'html.parser')

unicode_str = soup.decode("utf8")
encoded_str = unicode_str.encode("ascii",'ignore')
news_soup = BeautifulSoup(encoded_str, "html.parser")
a_text = news_soup.find_all('div')
print(a_text)
python html python-3.x selenium-webdriver beautifulsoup
1个回答
1
投票

这是因为谷歌地图被渲染为Angular的单页应用程序(我相信)。

BeautifulSoup无法执行Javascript,因此您需要执行Javascript代码(例如:使用SeleniumSplash或任何无头浏览器),然后才能实际查看和抓取呈现的HTML。

请参阅此存储库,其中包含您尝试实现的示例:https://github.com/registerguard/spa_scraper

您可以通过在浏览器中禁用Javascript并转到谷歌地图来见证我所说的内容。

© www.soinside.com 2019 - 2024. All rights reserved.