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