一、import urllib2if __name__ == '__main__' : url = 'http://www.baidu.com' proxy = {'http':'124.235.181.175:80'}
一.import urllib2if __name__ == '__main__' : url = 'http://www.csdn.net' head ={} head['User-Agent'] = 'Mozilla/5.0
1.URLErrorimporturllib2ifname=='main':url='http://www.567.com'req=urllib2.Request(url)try:response=urllib2.urlopen(req)#printresponsehtml=response.read().decode('utf-8')printhtmlexcepturllib2.
1、查找网页utf编码importurllibifname=='main':req=urllib.urlopen('自己想查看的网址')html=req.read()dehtml=html.decode('utf-8')printdehtml2、自动获取网页编码安装chardetpython-mpipinstallchardetimporturllibimportchardetif
Copyright © 2005-2024 51CTO.COM 版权所有 京ICP证060544号