By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,735 Members | 1,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,735 IT Pros & Developers. It's quick & easy.

how to judge urllib.Request is finished?

P: n/a
currently I am using
Expand|Select|Wrap|Line Numbers
  1. req=urllib2.Request(url)
  2. data=''
  3. if '</htm>' not in data:
  4. fd=urllib2.urlopen(req)
  5. data=fd.read()
  6. time.sleep(10)
  7. time.sleep(10)
  8. blahblah
  9.  
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?
Jul 1 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
On Tue, 01 Jul 2008 15:16:03 +0800, oyster wrote:
currently I am using
Expand|Select|Wrap|Line Numbers
  1. req=urllib2.Request(url)
  2. data=''
  3. if '</htm>' not in data:
  4.         fd=urllib2.urlopen(req)
  5.         data=fd.read()
  6.         time.sleep(10)
  7. time.sleep(10)
  8. blahblah
  9.  
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
Jul 1 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.