码迷,mamicode.com
首页 > 编程语言 > 详细

Python获取web页面信息

时间:2015-12-28 23:16:29      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:

1 import sys, urllib2
2 # req = urllib2.Request(sys.argv[1])
3 req = urllib2.Request(http://www.sina.com.cn)
4 fd = urllib2.urlopen(req)
5 print "Retrieved", fd.geturl()
6 info = fd.info()
7 for key, value in info.items():
8     print "%s = %s" % (key, value)

结果如下:

Retrieved http://www.sina.com.cn
content-length = 117199
x-cache = HIT from cnc.sy.1cf2.32.spool.sina.com.cn
x-powered-by = shci_v1.03
content-encoding = gzip
age = 3
expires = Mon, 28 Dec 2015 13:59:14 GMT
vary = Accept-Encoding
server = nginx
last-modified = Mon, 28 Dec 2015 13:57:24 GMT
connection = close
cache-control = max-age=60
date = Mon, 28 Dec 2015 13:58:14 GMT
content-type = text/html

 

Python获取web页面信息

标签:

原文地址:http://www.cnblogs.com/imzye/p/5084164.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!