当我使用python请求检查网站时,如果该网站将我重定向到另一个页面,我知道吗? [英] When I use python requests to check a site, if the site redirects me to another page, will I know?

查看:185
本文介绍了当我使用python请求检查网站时,如果该网站将我重定向到另一个页面,我知道吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是,如果我转到"www.yahoo.com/thispage",并且yahoo设置了过滤器,以将/thispage重定向到/thatpage.因此,每当有人访问/thispage时,他/他都会登陆/thatpage.

What I mean is, if I go to "www.yahoo.com/thispage", and yahoo has set up a filter to redirect /thispage to /thatpage. So whenever someone goes to /thispage, s/he will land on /thatpage.

如果我使用httplib/requests/urllib,它将知道存在重定向吗?什么错误页面? 每当找不到页面时,某些站点会将用户重定向到/errorpage.

If I use httplib/requests/urllib, will it know that there was a redirection? What error pages? Some sites redirect user to /errorpage whenever the page cannot be found.

推荐答案

使用requests,您可以在响应对象的.history属性中获得所有重定向的列表.它返回一个Python列表.有关更多信息,请参见文档.

With requests, you get a listing of any redirects in the .history attribute of the response object. It returns a Python list. See the documentation for more.

这篇关于当我使用python请求检查网站时,如果该网站将我重定向到另一个页面,我知道吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆