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,模拟浏览器

 

posted @ 2016-01-18 09:51  fj0716  阅读(140)  评论(0编辑  收藏  举报