你需要调用read
的返回值urllib2.urlopen
; 返回值urllib2.urlopen
不是字符串,而是连接对象(类文件对象)
刚申请re.findall
到的data
.
\d
不需要方括号.
import re import urllib2 data = urllib2.urlopen("http://python-data.dr-chuck.net/regex_sum_179860.txt").read() int_list = map(int, re.findall(r'\d+', data))
>>> int_list [3524, 9968, 6177, 3133, 6508, 7940, 3738, 1112, 6179, 4570, 6127, 9150, 9883, 418, 3538, 2992, 8527, 1150, 2049, 2834, 2630, 3840, 2638, 3800, 9144, 5866, 6742, 588, 6918, 7802, 8229, 7947, 8992, 1339, 2119, 846, 3820, 4070, 9356, 9708, 3238, 9380, 5572, 9491, 3038, 7434, 7771, 288, 8632, 3962, 9136, 8106, 7295, 3699, 4136, 3459, 8120, 6018, 8963, 5779, 3635, 3984, 4850, 9633, 2588, 7631, 9591, 1067, 7182, 1301, 8041, 1361, 5425, 8326, 7094, 8155, 2581, 7199, 6125, 42]