1 Star 0 Fork 4

神1様的男Ren/baidupan

forked from Chyroc/baidupan 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.py 1.19 KB
一键复制 编辑 原始数据 按行查看 历史
Chyroc 提交于 2015-10-30 16:32 . centos
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import urllib2
import redis
import json
r = redis.Redis(host='localhost', port=6379)
def get_pro():
try:
pro = r.spop('redis_pan_pro')
if pro == None:
try:
pros = urllib2.urlopen('http://chenapi.sinaapp.com/index.php/api').read()
for i in json.loads(pros):
r.sadd('redis_pan_pro',i)
return get_pro()
except Exception, e:
raise e
else:
return pro
except Exception, e:
raise e
def url_user_agent(url):
try:
try:
pro = get_pro()
except Exception, e:
raise Exception('get pro_http err')
proxy = {'http': pro}
proxy_support = urllib2.ProxyHandler(proxy)
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
i_headers = {
'Host':'www.baidu.com',
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36',
'Referer' : 'http://www.baidu.com',
'Connection' : 'keep-alive'
}
req = urllib2.Request(url,headers=i_headers)
return urllib2.urlopen(req,timeout=20).read()
except Exception, e:
raise e
print url_user_agent('http://pan.baidu.com/pcloud/friend/getfanslist?query_uk=3154767138&limit=24&start=0')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wikiblog/baidupan.git
git@gitee.com:wikiblog/baidupan.git
wikiblog
baidupan
baidupan
master

搜索帮助