python 爬虫学习

import json
import urllib.request
ua='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'
r=urllib.request.urlopen('http://httpbin.org/get')
req=urllib.request.Request("http://httpbin.org/user-agent")
req.add_header('User-Agent',ua)
r=urllib.request.urlopen(req)
r=r.read().decode()
rsp=json.loads(r)
print(rsp.get('user-agent'))

看USERAGENT                                   urllib库

 

2.REQUEST库

posted on 2019-10-11 23:32  土豆爸  阅读(138)  评论(0编辑  收藏  举报

导航