【问题标题】:Using Python to scrape point information from embedded google map使用 Python 从嵌入式谷歌地图中抓取点信息
【发布时间】:2020-05-02 08:56:07
【问题描述】:

我正在尝试使用请求库 + 美丽的汤从本网站显示的地图中提取有关天线点的信息。

http://www.sites.bipt.be/

我最初的计划是遍历站点编号,在单击某个点时提取左侧面板上显示的纬度/经度信息,然后在 Arc 中显示该数据。到目前为止,我已经访问了单击该点时该信息所在的元素( id = selectedsite ... )。但是该元素在 python 中显示为空,似乎是因为没有点击任何内容?

这是我第一次进行网络抓取,我的 HTML 知识有限,如果有其他更好的方法或您可以提供的任何指针将不胜感激:)

    import requests
    from bs4 import BeautifulSoup

    #api_key = 'MY_API_KEY'

    #Prettify HTML
    source = requests.get("http://www.sites.bipt.be/").text
    soup = BeautifulSoup(source, 'lxml')
    print(soup.prettify())


    # Class where information on the selected site is located - turns up empty
    div = soup.find(id='selectedsite')
    print(div.prettify())

【问题讨论】:

  • 你必须使用soup.find('div', {'id': 'selectedsite'})
  • 我已从您的问题中删除了您的 API 密钥。请不要在公共网站上共享私有 API 密钥,并确保按照 developers.google.com/maps/… 限制它们

标签: python html google-maps web-scraping screen-scraping


【解决方案1】:

此网页使用JavaScript 加载数据。您不能使用BeautifulSoup 单击网页中的元素。你必须使用selenium

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    • 2022-10-05
    • 2018-06-09
    • 2020-11-14
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多