首页 > 解决方案 > 使用 python 读取网站上的脚本

问题描述

我目前正在尝试编写一个 python 脚本,当网站更新它的公寓选择时,它会通过邮件通知我。但是,当我使用 Beautiful Soup 时,该站点不会返回项目列表,而是选择所有相关房屋的脚本,而不是所述脚本的结果。我有什么方法可以检索我通常作为用户看到的网站文本的 html 吗?这是我编写的相当简单的代码,以防万一。

html = #somesite
response = requests.get(html)
text = BeautifulSoup(response.text)
text.find_all("script")

标签: pythonhtmlbeautifulsoup

解决方案


html = #somesite
response = requests.get(html)
text = BeautifulSoup(response.text)
text.text # returns text in the entire html body, excluding script

推荐阅读