爬虫腾讯招聘的python岗位请用requests抓取后端的json数据包,拿到详情页的所有招聘信息
时间: 2024-05-03 11:21:50 浏览: 8
抓取腾讯招聘的json数据包可以使用requests库来实现。以下是示例代码:
```python
import requests
url = "https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1619591672522&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=40001&attrId=&keyword=&pageIndex=1&pageSize=10&language=zh-cn&area=cn"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
for job in data['Data']['Posts']:
print(job['RecruitPostName'], job['LocationName'], job['LastUpdateTime'], job['Responsibility'])
else:
print("请求失败")
```
上述代码中,首先我们使用requests库发送GET请求获取指定url的响应。然后根据响应的状态码是否为200来判断请求是否成功。如果成功,我们可以通过response.json()方法将响应的json数据转换为python对象,进而获取其中的招聘信息。最后,我们将招聘信息输出到控制台上。
相关问题
python爬虫腾讯招聘网站抓取json包数据
以下是一个简单的Python爬虫程序,用于从腾讯招聘网站抓取JSON包数据:
```python
import requests
url = 'https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1621982701417&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=40001&attrId=&keyword=&pageIndex=1&pageSize=10&language=zh-cn&area=cn'
response = requests.get(url)
data = response.json()
print(data)
```
该程序使用requests库发送HTTP GET请求,获取腾讯招聘网站的JSON数据。然后,将响应对象的json()方法调用,将JSON字符串转换为Python字典对象。
请注意,上面的URL是一个示例,可能需要根据实际情况进行修改。另外,网站的API可能需要身份验证或其他参数,因此您需要仔细查看网站的文档和API参考。
腾讯招聘岗位爬虫python
以下是使用Python进行腾讯招聘岗位爬虫的示例代码:
```python
import requests
def get_job_positions(keyword):
url = "https://careers.tencent.com/tencentcareer/api/post/Query"
params = {
"timestamp": "1637684846385",
"keyword": keyword,
"pageIndex": "1",
"pageSize": "10",
"language": "zh-cn",
"area": "cn"
}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36"
}
response = requests.get(url, params=params, headers=headers)
data = response.json()
job_positions = []
for item in data["Data"]["Posts"]:
job_positions.append(item["RecruitPostName"])
return job_positions
keyword = "python"
positions = get_job_positions(keyword)
for position in positions:
print(position)
```
这段代码使用了requests库发送GET请求,获取腾讯招聘网站上与关键字匹配的岗位信息。通过解析返回的JSON数据,提取出岗位名称并打印出来。