Finding Default Page Name using urllib2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • barrett

    Finding Default Page Name using urllib2

    Is there a way to find the name of a page you are retrieving using
    python. For example, if I get http://www.cnn.com/ i want to know that
    the page is index.html. I can do this using wget. as seen in the code
    below. Can I do this in python?

    Thanks,

    $ wget cnn.com
    --11:15:25-- http://cnn.com/
    =`index.html'
    Resolving cnn.com... 157.166.226.25, 157.166.226.26,
    157.166.224.25, ...
    Connecting to cnn.com|157.166 .226.25|:80... connected.
    HTTP request sent, awaiting response... 301 Moved Permanently
    Location: http://www.cnn.com/ [following]
    --11:15:25-- http://www.cnn.com/
    =`index.html'
    Resolving www.cnn.com... 157.166.224.25, 157.166.224.26,
    157.166.226.25, ...
    Reusing existing connection to cnn.com:80.
    HTTP request sent, awaiting response... 200 OK
    Length: 96,094 (94K) [text/html]

    100%[=============== =============== ======>] 96,094 68.15K/s

    11:15:28 (67.99 KB/s) - `index.html' saved [96094/96094]
  • Philip Semanchuk

    #2
    Re: Finding Default Page Name using urllib2


    On Oct 27, 2008, at 12:17 PM, barrett wrote:
    Is there a way to find the name of a page you are retrieving using
    python. For example, if I get http://www.cnn.com/ i want to know that
    the page is index.html. I can do this using wget. as seen in the code
    below. Can I do this in python?
    Hi barrett,
    Look into the urllib2 module and specifically HTTPRedirectHan dler
    objects.


    Good luck
    Philip

    Comment

    • Méta-MCI \(MVP\)

      #3
      Re: Finding Default Page Name using urllib2

      Hi!
      Can I do this in python?
      No.
      The "default page" is a property of the web-server ; and it is not
      client side.
      Examples :
      for Apache, it's index.html or index.htm ; but if PHP is installed,
      index.php is also possible.
      for APS, it's init.htm (between others possibilites).
      etc.

      @-salutations
      --
      Michel Claveau



      Comment

      Working...