python3.x 和 python2.x關於 urllib的用法

在python2.x版本中能夠直接使用import urllib來進行操做,可是python3.x版本中使用的是import urllib.request來進行操做,下面是簡單的例子:php

 

python2.xpython

  

import urllib  
url = 'http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345'  
text = urllib.urlopen(url).read()  

  

python3.xpython3.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)  
相關文章
相關標籤/搜索