Skip to content

Instantly share code, notes, and snippets.

@phyng
Last active August 7, 2021 10:56
Show Gist options
  • Save phyng/c2facd4057829a2982cf to your computer and use it in GitHub Desktop.
Save phyng/c2facd4057829a2982cf to your computer and use it in GitHub Desktop.
测试百度服务对不同referer的响应
import requests
referers = [
'',
'https://www.v2ex.com/',
'https://www.xxoo.com/',
'https://www.google.com/',
'http://www.baidu.com/',
'http://www.sogou.com/',
'http://www.so.com/',
'http://www.soso.com/',
'http://cn.bing.com/',
]
urls = [
'http://pan.baidu.com/share/link?shareid=1268793885&uk=2989926935',
'http://hi.baidu.com/zgj1986z'
]
for url in urls:
print '===TEST', url
for referer in referers:
headers = {'referer': referer}
r = requests.get(url, allow_redirects=False, headers = headers)
location=''
if 'location' in r.headers:
location = r.headers['location']
print '{:<25s}{:<5d}{:<25s}'.format(
referer, r.status_code, location)
===OUTPUT===
===TEST http://pan.baidu.com/share/link?shareid=1268793885&uk=2989926935
200
https://www.v2ex.com/ 200
https://www.xxoo.com/ 200
https://www.google.com/ 302 http://pan.baidu.com/error/404.html
http://www.baidu.com/ 302 http://pan.baidu.com/error/404.html
http://www.sogou.com/ 302 http://pan.baidu.com/error/404.html
http://www.so.com/ 302 http://pan.baidu.com/error/404.html
http://www.soso.com/ 302 http://pan.baidu.com/error/404.html
http://cn.bing.com/ 302 http://pan.baidu.com/error/404.html
===TEST http://hi.baidu.com/zgj1986z
200
https://www.v2ex.com/ 200
https://www.xxoo.com/ 200
https://www.google.com/ 302 http://hi.baidu.com/index/
http://www.baidu.com/ 200
http://www.sogou.com/ 302 http://hi.baidu.com/index/
http://www.so.com/ 302 http://hi.baidu.com/index/
http://www.soso.com/ 302 http://hi.baidu.com/index/
http://cn.bing.com/ 302 http://hi.baidu.com/index/
@phyng
Copy link
Author

phyng commented Jan 14, 2015


===TEST http://pan.baidu.com/share/link?shareid=1268793885&uk=2989926935
                         200                           
https://www.v2ex.com/    200                           
https://www.xxoo.com/    200                           
https://www.google.com/  302  http://pan.baidu.com/error/404.html
http://www.baidu.com/    302  http://pan.baidu.com/error/404.html
http://www.sogou.com/    302  http://pan.baidu.com/error/404.html
http://www.so.com/       302  http://pan.baidu.com/error/404.html
http://www.soso.com/     302  http://pan.baidu.com/error/404.html
http://cn.bing.com/      302  http://pan.baidu.com/error/404.html
===TEST http://hi.baidu.com/zgj1986z
                         200                           
https://www.v2ex.com/    200                           
https://www.xxoo.com/    200                           
https://www.google.com/  302  http://hi.baidu.com/index/
http://www.baidu.com/    200                           
http://www.sogou.com/    302  http://hi.baidu.com/index/
http://www.so.com/       302  http://hi.baidu.com/index/
http://www.soso.com/     302  http://hi.baidu.com/index/
http://cn.bing.com/      302  http://hi.baidu.com/index/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment