how to judge urllib.Request is finished?

O

oyster

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?
 
M

Marc 'BlackJack' Rintsch

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top