代码如下:
**
“`
from urllib import request,parse
url =’https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false’
header={‘User-Agent’: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106
Safari/537.36’,
‘Referer’: ‘https://www.lagou.com/jobs/list_python?city=%E5%85%A8%E5%9B%BD&cl=false&fromSearch=true&labelWords=&suginput=‘}
data = {
‘first’:’true’,
‘pn’:’1’,
‘kd’:’python’ }
re = request.Request(url,headers=header,data=parse.urlencode(data).encode(‘utf-8’),method=’POST’)#data中传入的数据需要转换编码格式
rea = request.urlopen(re) print(rea.read().decode(‘utf-8’))
**
伪装的更像浏览器行为一些就可以。