Parsing data from URL

H

Harlin Seritt

I am trying to do the following:

<of course website.com is not the actual site>

import urllib

url = 'http://www.website.com/file.shtml'
dat = urllib.urlopen(url, 'r').read()
print dat

When I do so, I get the following data:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>405 Method Not Allowed</TITLE>
</HEAD><BODY>
<H1>Method Not Allowed</H1>
The requested method POST is not allowed for the URL <P>
<HR>
<ADDRESS>Apache/1.3.27 Server at website.com Port 80</ADDRESS>
</BODY></HTML>

How can I make sure that I get the actual html data instead of the data
from redirected URL?

thanks,

Harlin
 
R

R. C. James Harlow

dat = urllib.urlopen(url, 'r').read()

Drop the 'r' - urlopen is posting the 'r' to the server, instead of doing what
you mean, opening the file read-only.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQBCbFAxY6W16wIJgxQRAglyAJ0QLdG8MDmUUpZjhQIbxV2QIr0CgwCcDu17
/I7VIjGXvvmAphR+FODCJqo=
=JwOd
-----END PGP SIGNATURE-----
 
K

Kartic

"The Great 'Harlin Seritt' uttered these words" on 4/24/2005 8:24 PM:
How can I make sure that I get the actual html data instead of the data
from redirected URL?

thanks,

Harlin

Harlin,

I am not sure I understand what you are asking but please see if the
below mentioned link will help you. I am just sending the URL that I
believe is relevant to you. You may want to read the entire chapter if
you are interested.

http://diveintopython.org/http_web_services/redirects.html

(Dive into Python's Chapter 11.7. Handling redirects)

Thanks,
-Kartic
 

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