urllib2 meta-refresh

Dave Brueck dave at pythonapocrypha.com
Sat Feb 26 01:05:55 EST 2005


Artificial Life wrote:
> urllib2 does not seem to be able to handle META-REFRESH in an html
> document. I just get back the html to the page that is supposed to forward
> me to the intended page.

Right - urllib2 is for working with protocols (like HTTP) to transfer data, 
whereas META-REFRESH is an application (browser) level "instruction" *in* that 
data. Compare this to a 302 HTTP response header (a simple redirect) - urllib2 
can handle it because it is part of HTTP.

> Any way around this? 

Sure - META-REFRESH is an instruction to the browser, so have your code be the 
browser: scan the HTML for the tag, extract the URL, and send that new URL off 
to urllib2.

-Dave



More information about the Python-list mailing list