Python3.6.6或许说python3.x找没有到urllib2语法成绩修正之后,会报一个不装置urllib2的包的谬误。
经过pip install urllib2也会提醒找没有到包。(保举学习:Python视频教程)
经过pip3 install urllib2也会提醒找没有到包。
这是由于builtwith依赖于urllib2包。但Pyhton2中的urllib2对象包,正在Python3中分拆成为了urllib.request以及urllib.error两个包。就招致找没有到包,同时也没方法装置。
以是需求install urllib.request以及install urllib.error 两个包,而后将builtwith包中的import urllib2修正为import urllib.request 以及import urllib.error。
同时代码中的办法函数也需求修正,根本就是将urllib2.xxx修正为urllib.request.xxx。
上面提供一个实例,协助各人了解:
#下载网页 import urllib.request import urllib.error def download(url): print('Downloading:',url) try: html=urllib.request.urlopen(url).read() except urllib.error as e: print('download error:',e.reason) html=None return html download('http://example.webscraping.com/')
更多Python相干技巧文章,请拜访Python教程栏目进行学习!
以上就是python3.6想应用urllib2包怎样办的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!