python - Can a URL be opened with a limit on the number of lines returned using urllib2? -


i know might sound ridiculous, possible use urllib2 open url, set number of lines returned?

the reason reduce load time, large pages working with. example, page:

1. <html> 2.  <head> 3.   <title>hello!</title> 4.  </head> 5.  <body> 6.   <p>hi there.</p> 7.  </body> 8. </html> 

say open page line 5, , printing once has been read, give me:

1. <html> 2.  <head> 3.   <title>hello!</title> 4.  </head> 5.  <body> 

is possible @ all?

sure is, can use readline() instead of read()

import urllib2  req = urllib2.request('http://www.python.org') response = urllib2.urlopen(req)  lines = "" x in range(10):         lines += response.readline()  print(lines) 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -