How to grab a part of web page?

Gerhard Häring gerhard.haering at gmx.de
Tue Jul 9 23:13:34 EDT 2002


* A <printers at sendme.cz> [2002-07-09 22:47 +0200]:
> Hi,
> Is it possible to download only a part of web page?

Yes, but the file-like objects returned by python's urllib don't support
seek(), yet.

> [...] Is it possible to use httplib or necessary socket module?

httplib is quite possible, and what the section that this example
prints, explains how it works:

from httplib import HTTPConnection

conn = HTTPConnection("www.ietf.org:80")

# Bytes form 100 onward
#conn.request("GET", "/rfc/rfc2616.txt", headers={"Range": "bytes=100-"})

# The RFC section describing the Range header
conn.request("GET", "/rfc/rfc2616.txt", headers={"Range": "bytes=336069-341643"})

# Last 100 bytes
#conn.request("GET", "/rfc/rfc2616.txt", headers={"Range": "bytes=-100"})

resp = conn.getresponse()
print resp.read()

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 17.7 °C      Wind: 2.1 m/s





More information about the Python-list mailing list