【问题标题】:Web Scraping beautifulsoup not showing node contentWeb Scraping beautifulsoup 不显示节点内容
【发布时间】:2021-07-31 14:52:08
【问题描述】:

我正在尝试抓取以下 URL: “https://www.licitor.com/ventes-judiciaires-immobilieres/tj-pontoise/mardi-7-septembre-2021.html”。

然后可以使用不同的项目,比如说项目编号 086276,这给出了例如以下 URL: https://www.licitor.com/ventes-judiciaires-immobilieres/tj-pontoise/mardi-7-septembre-2021.html#086276

我对以下节点的内容特别感兴趣:

"<article class="LegalAd"></article>"

我目前使用以下代码:

URL = "https://www.licitor.com/ventes-judiciaires-immobilieres/tj-pontoise/mardi-7-septembre-2021.html#086276"
page = requests.get(URL)

soup = BeautifulSoup(page.content, "html.parser")

这确实给了我一个输出,但是,在查看此输出时,“LegalAd”的内容不存在。 在使用 Chrome 检查元素时,我可以看到 html 代码并在“LegalAd”中导航,但是在将其引入 Python 时,这似乎并没有遵循...

有人知道为什么节点的内容会被隐藏吗?有人有解决办法或想法吗?

【问题讨论】:

  • 就在那里,使用page.text获取内容
  • @Epsi95 我不这么认为——元素在那里,但 .text 在 JS 执行之前是空的。

标签: python html web-scraping beautifulsoup


【解决方案1】:

HTML 是从另一个端点和injected dynamically into the div using JS 获取的。这段代码只是直接转到数据静态存在的另一个端点:

import requests
from bs4 import BeautifulSoup

URL = "https://www.licitor.com/annonce/08/62/76/vente-aux-encheres/un-appartement/argenteuil/val-d-oise/086276.html"
response = requests.get(URL)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
print(soup.select_one(".LegalAd"))

我通过在开发人员工具的网络选项卡中搜索目标元素中出现的单词之一发现了这一点:

顶部“mardi”的结果似乎是移动版本。

【讨论】:

    猜你喜欢
    • 2021-09-03
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 2018-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-13
    相关资源
    最近更新 更多