python requests(一) 与urllib2

# -*- coding:utf-8 -*-
import urllib2
import urllib
url = 'http://ah.example.com'
half_url = u'/servlet/av/jd?ai=782&ji=2624743&sn=I'
#构造get请求
req = urllib2.Request(url+half_url.encode('utf-8'))
#添加header
req.add_header('Accept-Encoding', 'gzip,deflate')
req.add_header('User-Agent','Mozilla/5.0')
response = urllib2.urlopen(req)
print response
        resp2 = urllib2.Request(url,headers = get_header())
        r = urllib2.urlopen(resp2)
        print r.headers

你可能感兴趣的:(python requests(一) 与urllib2)