python - 使用 "show more "来抓取数据

标签 python parsing button screen-scraping show

我一直在尝试使用 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/

相关文章:

ios - 我应该为我拥有的每个 XML 提要使用一个 XML 解析器,还是应该为我拥有的每个 XML 提要编写一个解析器?

python - 如何从节点及其子节点列表中生成 NLTK 中的括号树字符串

python - wxPython按钮加载多个图像

python - 替换 numpy 中的前 10 个值

parsing - 解析事件日志文件

Android/Kotlin - 如何循环所有 ToggleButtons 以形成 if/else 的条件

python - PyQt : Adding rows to QTableView using QAbstractTableModel

python - 如何在另一个 python 文件中运行我的 python 文件?

python - 如何获得对 Pocket Sphinx 转录的信心

python - 如何使用 setup.py 安装 wheel-style 包