python - 当提供的数据是 XML 时,如何从检查菜单中检索相同的 HTML?
问题描述
我正在使用 Python 的request
模块来抓取这个网站:http ://reports.ieso.ca/public/Adequacy2/PUB_Adequacy2_20200114.xml
import requests
def get_info(date=None):
headers = {
"Content-Type": "text/html"
}
response = requests.get('http://reports.ieso.ca/public/Adequacy2/PUB_Adequacy2_20200114.xml', headers=headers,verify=False)
print(response.text)
return response
get_info()
现在它返回 XML,我理解。但是当我检查那个网站时,我看到的 HTML 结构是不同的,而且它的结构要好得多。
有没有办法通过请求而不是 XML 数据来获取该数据?还是其他替代方案?
解决方案
我认为美丽的汤可能会满足您的要求。
装美汤
pip3 install beautifulsoup4
“汤”对象有望解析为您所期望的
import requests
from bs4 import BeautifulSoup
URL = 'https://www.monster.com/jobs/search/?q=Software-Developer&where=Australia'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
推荐阅读
- regex - 正则表达式 - 文件名与所需模式不匹配
- git - 如何从 Execute Shell 引用 Jenkins Github 存储库名称?
- angular - 我想使用带有验证器的反应式表单一次显示一个错误
- jmeter - Jmeter:通过发布请求发送cookie时会话过期
- c++ - 向量中的 std::sort
返回 0 而不是值 - reactjs - 尝试从 Babel 6 升级到 Babel 7 时,webpack 模块构建失败
- python - Python 在初始化期间更改实例的属性
- java - 为什么与我的外部数据库(Spring/JpaRepository)没有连接?
- android - Gradle 排除依赖从内置 apk 导入的 lib
- javascript - 添加