2013-04-28 34 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

相关问题