从 javascript 生成的 html 文档中提取数据时出现问题

Issue with extracting data from javascript generated html doc

提问人:Jensen Benny 提问时间:9/11/2023 最后编辑:Jensen Benny 更新时间:9/11/2023 访问量:18

问:

我正在尝试解析此页面中的信息 https://fem.encar.com/cars/detail/35902422?wtClick_index=187&conType=pctom 我需要的数据位于html的以下部分:

<span class="DetailSummary_num_graph__oN21B">
<span>82%</span>
</span>

我需要得到这 82%。

我保存了具有以下功能的html文件:

async def discount(folder):
    url = f"https://fem.encar.com/cars/detail/35902422?wtClick_index=187&conType=pctom"
    headers = {
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
    }

    async with aiohttp.ClientSession() as session:
        async with session.get(url=url, headers=headers) as response:
            data = await response.text()
            if not os.path.exists(folder):
                os.makedirs(folder)
            with open(f"{folder}\html.html", "w", encoding="utf8") as file:
                file.write(data)

但是,保存的 html 文档没有我在浏览器上看到的我需要的信息。请帮我在此网页上的json或其他类型的文件中找到此数据

Python HTML 解析 动态生成

评论

0赞 Jaromanda X 9/11/2023
虽然该文档中确实存在,但该跨度不包含跨度,它只是包含 - 无论如何,如果数据是动态检索的,那么您将需要一个浏览器来查看动态数据 - 显然,该站点是为了阻止 Web 抓取而制作的<span class="DetailSummary_num_graph__oN21B"-%

答: 暂无答案