python 3.x urllib学习

urllib.request

import urllib.request as ur
url='http://ie.icoa.cn'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
req=ur.Request(url)
req.add_header('User-Agent',user_agent)
res=ur.urlopen(req)
html=res.read().decode('utf8')
print(html)

发送一个header,模拟浏览器

 

你可能感兴趣的:(python 3.x urllib学习)