import re import urllib import urllib.request url = 'http://www.baidu.com' headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.104 Safari/537.36 Core/1.53.4620.400 QQBrowser/9.7.13014.400'} resquest = urllib.request.Request(url=url, headers=headers) response = urllib.request.urlopen(resquest).read() url = "http://www.baidu.com" # 请求 request = urllib.request.Request(url) # 爬取结果 response = urllib.request.urlopen(request) data = response.read() # 设置解码方式或者换成uft-8 data = data.decode('gbk') # 打印结果 print(data) # 打印爬取网页的各
python简单伪装和爬网页
最新推荐文章于 2024-07-12 17:01:23 发布