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

Parsing data from URL

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
I think it depends on the server

On 24 Apr 2005 17:24:18 -0700, Harlin Seritt <ha**********@yahoo.com> wrote:
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

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #2

P: n/a
On Monday 25 April 2005 01:24, Harlin Seritt wrote:
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)

iD8DBQBCbFAxY6W16wIJgxQRAglyAJ0QLdG8MDmUUpZjhQIbxV 2QIr0CgwCcDu17
/I7VIjGXvvmAphR+FODCJqo=
=JwOd
-----END PGP SIGNATURE-----

Jul 19 '05 #3

P: n/a
"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_s...redirects.html

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

Thanks,
-Kartic
Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.