首页 > 其他 > 详细

重定向请求

时间:2019-01-22 16:13:25      阅读:231      评论:0      收藏:0      [点我收藏+]

# coding:utf-8
import requests
# 请求头
headers = {
     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0"
          }
s = requests.session()
# 打开我的随笔
r = s.get(‘https://i.cnblogs.com/EditPosts.aspx?opt=1‘,
          headers=headers,
          allow_redirects=True, # 允许重定向, False不允许重定向
          verify=False)
# 打印状态码,自动处理重定向请求
print r.status_code
new_url = r.headers["Location"] # 获取重定向后的url
print new_url

重定向请求

原文:https://www.cnblogs.com/yaohu/p/10304336.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!