python废料数据美国政府

时间:2016-10-25 22:49:52

标签: python sockets web

我收到以下错误

'IOError:[Errno套接字错误] [Errno -2]名称或服务未知'

当我尝试废弃数据时:

http://1usagov.measuredvoice.com/2013/

任何想法可能是什么原因?

这是我的代码:

import urllib
import re

import time

data = urllib.urlopen('http://1usagov.measuredvoice.com/2013/').read()
# print data
print data
# datafiles name pattern - usagov_bitly_data2011-07-29-1311919454
p = re.compile('usagov_bitly_data\d{4}-\d{2}-\d{2}-\d{10}')
# print p.findall('<tr><td valign="top"><img src="/icons/unknown.gif" alt="[   ]"></td><td><a href="usagov_bitly_data2011-07-29-1311919454">usagov_bitly_data2011-07-29-1311919454</a></td><td align="right">29-Jul-2011 07:04  </td><td')

m = p.findall(data)

# print m

for i in range(len(m)):
    if (i % 2 == 0):
        print m[i]

# time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch))

print len(m)

for i in range(len(m)):
    if (i % 2 == 0):
        print "downloading ", m[i]
        clicks = urllib.urlopen('http://bitly.measuredvoice.com/bitly_archive/' + m[i]).read()
        file = open(m[i], "w")
        file.write(clicks)
        file.close()
        print "done"

编辑:

添加完全追溯

Traceback (most recent call last):
  File "scrap.py", line 6, in <module>
    data = urllib.urlopen('http://1usagov.measuredvoice.com/2013/').read()
  File "/usr/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 345, in open_http
    h.endheaders(data)
  File "/usr/lib/python2.7/httplib.py", line 975, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 835, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 797, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 778, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 553, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
IOError: [Errno socket error] [Errno -2] Name or service not known

0 个答案:

没有答案