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

Finding Default Page Name using urllib2

P: n/a
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]
Oct 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a

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 HTTPRedirectHandler
objects.
Good luck
Philip
Oct 27 '08 #2

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

Oct 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.