python3.x 和 python2.x关于 urllib的用法
2016-07-10 16:34
357 查看
在python2.x版本中可以直接使用import
urllib来进行操作,但是python3.x版本中使用的是import urllib.request来进行操作,下面是简单的例子:
python2.x
import urllib
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'
text = urllib.urlopen(url).read()
python3.x
import urllib.request
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
current = '12345'
response = urllib.request.urlopen(url+current)
text = response.read()
current = text[-5:]
response = urllib.request.urlopen(url+current)
urllib来进行操作,但是python3.x版本中使用的是import urllib.request来进行操作,下面是简单的例子:
python2.x
import urllib
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'
text = urllib.urlopen(url).read()
python3.x
import urllib.request
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing='
current = '12345'
response = urllib.request.urlopen(url+current)
text = response.read()
current = text[-5:]
response = urllib.request.urlopen(url+current)
相关文章推荐
- Python使用urllib模块的urlopen超时问题解决方法
- Python3学习urllib的使用方法示例
- python基于urllib实现按照百度音乐分类下载mp3的方法
- Python urllib、urllib2、httplib抓取网页代码实例
- Python库urllib与urllib2主要区别分析
- Python中的urllib模块使用详解
- python中urllib模块用法实例详解
- python3使用urllib模块制作网络爬虫
- urllib.urlencode() 无法encode中文, UnicodeEncodeError
- python3使用urllib模块制作网络爬虫
- Python 10.9 urllib
- Python版本的发展
- urllib urllib2 自己用
- python 下载百度音乐
- python 3.x和2.x的区别
- Python抓取数据并存入到mysql
- Python学习之网页抓取(一)
- python3.x入手,修改了2.x的代码兼容3.x
- urllib中的urlretrieve提示错误:No such file or directory
- Python机器学习2-股票信息简单抓取