爬取第一步

1、第一打开网页》F12》network》停止,》查看headers》response headers中User-agent复制
2、

import urllib.request
import urllib.parse
#第一个表达
# headers={
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"
# }
# url='http://httpbin.org.post'
# data=bytes(urllib.parse.urlencode({'name':'eric'}),encoding='utf-8')
# req=urllib.request.Request(url=url,data=data,headers=headers,method='POST')
# response=urllib.request.urlopen(req)
# print(response.read().decode('utf-8'))




#第二个表达
#url='https://www.douban.com'
# headers={
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36"
# }
# req=urllib.request.Request(url=url,headers=headers)
# response=urllib.request.urlopen(req)
# print(response.read().decode('utf-8'))
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页