Parsing data from URL

Discussion in 'Python' started by Harlin Seritt, Apr 25, 2005.

  1. 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
     
    Harlin Seritt, Apr 25, 2005
    #1
    1. Advertising

  2. Harlin Seritt

    could ildg Guest

    I think it depends on the server

    On 24 Apr 2005 17:24:18 -0700, Harlin Seritt <> 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
    >
     
    could ildg, Apr 25, 2005
    #2
    1. Advertising

  3. 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)

    iD8DBQBCbFAxY6W16wIJgxQRAglyAJ0QLdG8MDmUUpZjhQIbxV2QIr0CgwCcDu17
    /I7VIjGXvvmAphR+FODCJqo=
    =JwOd
    -----END PGP SIGNATURE-----
     
    R. C. James Harlow, Apr 25, 2005
    #3
  4. Harlin Seritt

    Kartic Guest

    "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
     
    Kartic, Apr 26, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GIMME
    Replies:
    2
    Views:
    914
    GIMME
    Feb 11, 2004
  2. Jon paugh
    Replies:
    1
    Views:
    882
  3. Naren
    Replies:
    0
    Views:
    598
    Naren
    May 11, 2004
  4. Christopher Diggins
    Replies:
    0
    Views:
    623
    Christopher Diggins
    Jul 9, 2007
  5. Just D.
    Replies:
    0
    Views:
    509
    Just D.
    Aug 11, 2004
Loading...

Share This Page