python - 尝试使用 API 调用抓取网站
问题描述
我正在尝试使用 python 中的 API 调用来抓取网站https://www.jobijoba.com/fr/query/?what=&where=Ile-de-france&where_type=region 。我正在使用请求库来发送请求。但不幸的是,我无法访问数据。我在下面分享了我的代码。我怎样才能有效地抓取网站。我应该使用 selenium webdriver 来完成这项任务吗?任何帮助将非常感激。
import requests
headers = {
'Accept': '*/*',
'Referer': 'https://www.jobijoba.com/fr/query/?what=&where=Ile-de-france&where_type=region',
'X-Requested-With': 'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
}
data = {
'where': 'Ile-de-france',
'where_type': 'region',
'perimeter': '20',
'duration': '',
'period': '',
'publication': '',
'contract': '',
'formation': 'false',
'jobbing': 'false',
'page': '4',
'editor_id': '54'
}
response = requests.post('https://www.jobijoba.com/fr/url_api', headers=headers, data=data)
解决方案
您的脚本确实给出了响应,可以访问为
response.json()
我没有上下文来说明该响应的意义,但绝对有一个有效的 API 响应。
推荐阅读
- javascript - 为什么反应显示组件更新但控制台不更新?
- docker - 容器之间的连接被拒绝:Docker
- r - ggplot的色谱图
- asp.net-core-mvc - JsonRequestBehavior.AllowGet 在当前上下文中不存在
- mongodb - Mongoose .pull 不删除子文档
- java - 无法将孩子添加到firebase android中的现有孩子
- android - 如何从 Firestore 获取子集合数据
- c++ - 为什么命名空间中的函数看不到我的 operator<< 全局定义?
- javascript - 如何对对象内数组属性的长度求和
- html - 如何在文本周围放置边框(在 pesudo 类和填充相关之后的 CSS 之前)