爬虫02-简单伪装浏览器

from urllib import parse
from urllib import request
# url="https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput="
url="https://www.lagou.com/jobs/positionAjax.json?needAddtionalResult=false"
headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36",
         "Referer":"https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput="}

data={
    "frist":"ture",
    "pn":"1",
    "kd":"python"
}

req=request.Request(url,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/wcyMiracle/p/12460638.html