2013-04-28 47 views
-4

IM試圖讓代理出一個網頁的AttributeError的: '模塊' 對象有 '的urlopen' python2.7

import urllib 
import re 
myfile = open("C:\\Users\Teli\Desktop\pro.txt", "w") 
page = urllib.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read() 
a = re.findall('\d+\.\d+\.\d+\.\d+', page) 
myfile.write(str(a)) 
myfile.close() 

它爲什麼說不屬性:

page = urllib.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read() 

AttributeError: 'module' object has no attribute 'urlopen' 
+1

你確定你使用Python 2? – Blender 2013-04-28 21:17:47

+0

即時通訊使用python2.7 – 2013-04-28 21:23:00

+0

什麼'print(__ import __('sys')。version)'output? – Blender 2013-04-28 21:24:04

回答

0

我使用python2.7和它的工作

import urllib 
import re 
myfile = open("C:\\Users\Teli\Desktop\pro.txt", "w") 
pagea = urllib.urlopen("http://www.samair.ru/proxy/ip-address-01.htm").read() 
a = re.findall('\d+\.\d+\.\d+\.\d+', pagea) 
pageb = urllib.urlopen("http://www.samair.ru/proxy/ip-address-02.htm").read() 
b = re.findall('\d+\.\d+\.\d+\.\d+', pageb) 
pagec = urllib.urlopen("http://www.samair.ru/proxy/ip-address-03.htm").read() 
c = re.findall('\d+\.\d+\.\d+\.\d+', pagec) 
paged = urllib.urlopen("http://www.samair.ru/proxy/ip-address-04.htm").read() 
d = re.findall('\d+\.\d+\.\d+\.\d+', paged) 
myfile.write(str(a)) myfile.write(str(b)) myfile.write(str(c)) 
myfile.write(str(d)) myfile.close() 
+0

呵呵。帕維爾的回答正好描述了你的問題,但你決定不接受它作爲最好的答案。 – hughdbrown 2013-07-05 03:41:30

0

你不是使用python 3或在當前目錄中有一個名爲urllib.py的文件。

+0

我還沒用過python 3它的python 2.7 – 2013-04-28 21:23:37

+0

我設法使用它! – 2013-04-29 17:36:47

相關問題