当前位置:编程学习 > 网站相关 >>

python httplib获取location

#!/usr/bin/env python
# -*- coding:utf-8 -*-

import httplib

httplib.HTTPConnection.debuglevel = 1
'''
200正常状态码不会有跳转 也就不会有location
conn = httplib.HTTPConnection("tu.duowan.com") #这里是host
conn.request('GET', '/m/meinv/index.html')#上面是分支 注意是GET
'''
#访问跳转的302页面就可以在headers中找到location
conn = httplib.HTTPConnection("localhost") #这里是host
conn.request('GET', '/yesearch/index.php?r=site/index')#上面是分支 注意是GET
for item in conn.getresponse().getheaders(): 
if item[0]=='location':
print item[1]
conn.close()

 

 本地php构造一个redirect重定向 访问site/index 跳转到site/search路由。




用python httplib获得的headers里面就有location
补充:Web开发 , Python ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,