how to judge urllib.Request is finished?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • oyster

    #1

    how to judge urllib.Request is finished?

    currently I am using
    Code:
    req=urllib2.Request(url)
    data=''
    if '</htm>' not in data:
    fd=urllib2.urlopen(req)
    data=fd.read()
    time.sleep(10)
    time.sleep(10)
    blahblah
    Is there any other ready-to-use function? And what if the internet
    connection is chocked so that the html page can not be loaded
    entirely?
  • Marc 'BlackJack' Rintsch

    #2
    Re: how to judge urllib.Request is finished?

    On Tue, 01 Jul 2008 15:16:03 +0800, oyster wrote:
    currently I am using
    Code:
    req=urllib2.Request(url)
    data=''
    if '</htm>' not in data:
            fd=urllib2.urlopen(req)
            data=fd.read()
            time.sleep(10)
    time.sleep(10)
    blahblah
    That looks very strange. Why the ``if`` and the `sleep()`\s? The ``if``
    condition is always true, so it's completely unnecessary. The `read()`
    call is blocking, that means it returns iff the complete data is read. So
    there's no need to wait or to check if all is read. If there's a problem
    with the connection an exception should be raised by `urllib2`.

    Ciao,
    Marc 'BlackJack' Rintsch

    Comment

    Working...