
大家好,我是梦雅:mengy7762~
今天我们爬取腾讯招聘网站Python岗位的招聘信息。如图所示:

然后还是先看一下最终的结果,我们保存到csv文件中。
爬取1000条数据,第一行是title:

老规矩,我们还是走流程。
01需求分析
抓取腾讯招聘网站Python相关岗位数据,打开目标网站,F12打开开发者工具,发现岗位信息不在网页源码中,很明显是在XHR中的json数据。最后,如果你的时间不是很紧张,并且又想快速的提高,最重要的是不怕吃苦,建议你可以联系维:762459510 ,那个真的很不错,很多人进步都很快,需要你不怕吃苦哦!大家可以去添加上看一下~

正好对应页面十条数据,接下来就好办了。
02发送请求
找到url的页面规律,
url:https://careers.tencent.com/tencentcareer/api/post/Query?timestamp=1620561777984&countryId=&cityId=&bgIds=&productId=&categoryId=&parentCategoryId=&attrId=&keyword=python&pageIndex=1&pageSize=10&language=zh-cn&area=cn
index参数对应值即为页码,所以循环得到url链。
def?getPage(self):? ????????url_list?=?[]? ????????for?i?in?range(100):? ????????????url?=?self.url.format(i?+?1)? ????????????url_list.append(url)? ????????return?url_list
03解析页面
得到url链之后我们循环遍历发起请求,得到json数据,将json数据转换成字典,并解析数据。
for?url?in?urlList:
resp?=?requests.get(url,?headers=self.headers)
data?=?resp.content.decode(‘utf-8’)
dic_data?=?json.loads(data)
dic_data_list?=?dic_data[“Data”][“Posts”]
for?i?in?dic_data_list:
work_list.append(i)
这样就得到了岗位信息数据。

04保存数据
得到了岗位数据之后我们需要把它保存到本地,这里我们把数据保存到本地csv文件中。最后,如果你的时间不是很紧张,并且又想快速的提高,最重要的是不怕吃苦,建议你可以联系维:762459510 ,那个真的很不错,很多人进步都很快,需要你不怕吃苦哦!大家可以去添加上看一下~
try:? ????????????with?open(‘Tx_work.csv’,?‘w’,?encoding=‘utf-8’,?newline=’’)?as?f:? ????????????????writer?=?csv.DictWriter(f,?self.title)? ????????????????writer.writeheader()? ????????????????writer.writerows(dic)? ????????????????print(‘写入成功’)? ????????except?Exception?as?e:? ????????????print(e)
05运行程序
if?name?==?‘main’:? ????tx?=?Tx(base_url,hd,titles)? ????tx.run()

小伙伴们可以对Python岗位的岗位需求好好分析结合自身技术栈,最后希望大家都能找到好工作。
需要资料关注后私信“6”即可
|