python3中,使用get提交表单时怎样使用header
发布网友
发布时间:2022-04-23 01:10
我来回答
共1个回答
热心网友
时间:2022-04-18 03:48
def openUrl(url):
import urllib2
url = 'http://' + url
req = urllib2.Request(url)
//根据你自己的需要设置header,add_header方法中需要两个参数,key和value的键值对
req.add_header('User-agent', 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1707.0 Safari/537.36')
response = urllib2.urlopen(req)
the_page = response.read()
print the_page
print response.geturl()
print response.info()
print response.headers
openUrl('xxx.xxx.xxx')