爬虫02-简单伪装浏览器

Posted wcymiracle

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬虫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"))

  

以上是关于爬虫02-简单伪装浏览器的主要内容,如果未能解决你的问题,请参考以下文章

Python爬虫3-----浏览器伪装

Python网络爬虫:伪装浏览器

Python网络爬虫:伪装浏览器

Python网络爬虫:伪装浏览器

python爬虫之伪装浏览器

scrapy按顺序启动多个爬虫代码片段(python3)