我一直在尝试使用 python 从网页中抓取数据,到目前为止一切顺利。但问题是页面不会立即加载所有内容,有一个“显示更多”按钮。所以我的脚本只抓取前 10 项。 我查看了该网站,但对该网址无能为力。我想我必须向服务器发布一些内容才能取回下一个项目,但我不知道要发布什么以及如何发布。这是我的代码:
res = requests.get('https://candidat.pole-emploi.fr/offres/recherche?motsCles=serveur&offresPartenaires=true&rayon=20&tri=0')
page_soup = bs4.BeautifulSoup(res.text,"html.parser")
containers = page_soup.findAll("div",{"class":"media-body"})
url = []
for container in containers:
url.append('https://candidat.pole-emploi.fr' +container.h2.a["href"])
for i in url:
print(i)
email_list = []
for adress in url:
print( ' testing ', adress)
found = False
detail = requests.get(adress)
apply = bs4.BeautifulSoup(detail.text,"html.parser")
apply_mail = apply.findAll("div",{"class":"apply-block"})
if apply_mail == []:
email_list.append('not found')
continue
email_raw = apply_mail[0].text
for i in email_raw.splitlines():
if '@' in i:
email_list.append(i)
found = True
if not found:
email_list.append('not found')
for i in email_list:
print(i)
最佳答案
您可以使用 Beuatifulsoup
或其他 http
请求库废弃的唯一数据是在启动时可用的数据,而无需 Javascirpt
运行。它与curl $URL
和解析数据相同。
解决此问题的一种方法是使用 selenium
webdriver 和
编写与用户在浏览器上执行的操作相同的操作。
可以找到更多信息
关于python - 使用 "show more "来抓取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49887782/