首页 > 其他 > 详细

拉钩网————爬取尝试

时间:2018-08-05 12:50:54      阅读:191      评论:0      收藏:0      [点我收藏+]
  1.  #拉勾网需要User-Agent请求头才能获取到内容

 

from urllib import request

url="https://www.lagou.com/jobs/list_python%20?labelWords=&fromSearch=true&suginput="


headers = {
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
}


req = request.Request(url,headers=headers)

resp = request.urlopen(req)

print(resp.read())

 

 

 

 

2.json解析后的内容

技术分享图片

 

技术分享图片

 

技术分享图片

 3.尝试获取(需要User-Agent请求头以及Referer

from urllib import request,parse

#需要User-Agent请求头以及Referer

# url="https://www.lagou.com/jobs/list_python%20?labelWords=&fromSearch=true&suginput="
urlajax="https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false"


headers = {
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.96 Safari/537.36,
 Referer: https://www.lagou.com/jobs/list_python%20?labelWords=&fromSearch=true&suginput=
}

data={
first:true,
pn:1,
kd:python
}


req = request.Request(urlajax,headers=headers,data=parse.urlencode(data).encode(utf-8),method=POST)

resp = request.urlopen(req)

print(resp.read().decode(utf-8))

 技术分享图片

 

拉钩网————爬取尝试

原文:https://www.cnblogs.com/834477300j/p/9424886.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!