gpt4 book ai didi

python - 浏览器中的 HTML 与 python 中抓取的数据不对应

转载 作者:太空宇宙 更新时间:2023-11-03 15:49:36 24 4
gpt4 key购买 nike

对于一个项目,我必须从不同的网站上删除数据,但我遇到了问题。

当我查看源代码时,我想要的东西都在表格中,所以它似乎很容易废弃。但是当我运行我的脚本时,部分代码源不会显示。

这是我的代码。我尝试了不同的事情。起初没有任何标题,然后我添加了一些但没有区别。

# import libraries
import urllib2
from bs4 import BeautifulSoup
import csv
import requests

# specify the url
quote_page = 'http://www.airpl.org/Pollens/pollinariums-sentinelles'

# query the website and return the html to the variable 'page'
response = requests.get(quote_page)
response.addheaders = [('User-agent', 'Mozilla/5.0')]
print(response.text)

# parse the html using beautiful soap and store in variable `response`
soup = BeautifulSoup(response.text, 'html.parser')

with open('allergene.txt', 'w') as f:
f.write(soup.encode('UTF-8', 'ignore'))

我在网站中寻找的是“Herbacée”之后的内容,其 HTML 如下:

<p class="level1">

<img src="/static/img/state-0.png" alt="pas d'émission" class="state">

Herbacee
</p>

你知道出了什么问题吗?

感谢您的帮助,祝大家新年快乐:)

最佳答案

该页面使用JavaScript来渲染表格,真正包含表格的页面是:

http://www.alertepollens.org/gardens/garden/1/state/

您可以在 Chrome 开发工具>>>网络中找到此网址。

enter image description here

关于python - 浏览器中的 HTML 与 python 中抓取的数据不对应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41429440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com