python3.x 和 python2.x关于 urllib的用法

在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)  

  

posted @ 2017-03-28 21:05  dy9776  阅读(822)  评论(0编辑  收藏  举报