import urllib.request
import http.cookiejar
import urllib.error
import requests
import zlib
url = 'https://www.baidu.com'
# 配置爬取选项
cjar = http.cookiejar.CookieJar()
proxy = urllib.request.ProxyHandler({'http':'127.0.0.1:8888'})
opener = urllib.request.build_opener(proxy,urllib.request.HTTPHandler\
,urllib.request.HTTPCookieProcessor(cjar))
# -----------------------------------------------------------------------------
# 添加浏览器伪装,下述内容为Fiddler的浏览器截获内容
# GET / HTTP/1.1
# Host: www.sina.com.cn
# User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0
# Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
# Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
# Accept-Encoding: gzip, deflate
# Connection: keep-alive
# Upgrade-Insecure-Requests: 1
headers_all = []
headers = {
'User-Agent':'
爬取网页浏览器伪装
最新推荐文章于 2020-06-18 21:48:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)