Jump to content
Fórum Script Brasil
  • 0

urllib2.URLError


KamillaaaH

Question

Olá! Estou iniciando um sistema de web scraping e tentando pegar o conteúdo de algumas páginas de feeds com o seguinte código:

# -*- coding: utf-8 *-*
from urllib2 import urlopen
from xml.sax import make_parser, ContentHandler


class RSSHandler(ContentHandler):

    def __init__(self):
        ContentHandler.__init__(self)
        self.__inItem = False
        self.__inTitle = False

    def characters(self, data):
        if self.__inTitle:
            print data

    def startElement(self, tag, attrs):
        if tag == "item":
            self.__inItem = True

        if tag == "title" and self.__inItem:
            self.__inTitle = True

    def endElement(self, tag):
        if tag == "title" and self.__inTitle:
            self.__inTitle = False
            print("\n")
        if tag == "item":
            self.__inItem = False


def listFeedTitle(url):
    infile = urlopen(url)
    parser = make_parser()
    parser.setContentHandler(RSSHandler())
    parser.parse(infile)

#listFeedTitle("http://feeds.feedburner.com")
listFeedTitle("http://9gag.com/rss/site/feed.rss")
Só que obtenho o seguinte erro (mesmo com diferentes urls de feeds):
Traceback (most recent call last):
  File "RSSHandler.py", line 39, in <module>
    listFeedTitle("http://9gag.com/rss/site/feed.rss")
  File "RSSHandler.py", line 33, in listFeedTitle
    infile = urlopen(url)
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 394, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 412, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1201, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.7/urllib2.py", line 1171, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>

Não uso nenhum tipo de proxy e não consegui achar nada que resolvesse o problema. Alguém tem idéia do que pode ser?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...