1 Star 0 Fork 0

李贞/stock_selection

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
safari.py 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
yanheven 提交于 2016-04-26 10:58 . fix message
__author__ = 'evan'
import requests
pre_url = 'https://www.safaribooksonline.com/library/view/openstack-in-action/9781617292163/'
mid_url = 'fig'
alt_url = '_alt'
end_rul = '.jpg'
chapters = {'a0': 41,
'01': 8,
'02': 19,
'03': 16,
'04': 18,
'05': 7,
'06': 14,
'07': 7,
'08': 4,
'9': 6,
'10': 2,
'11': 18,
'12': 10}
# def get_jpb(url):
#
for ch, total in chapters.items():
for i in xrange(1, int(total) + 1):
index = str(i)
if i < 10:
index = '0' + str(i)
preurl = pre_url + ch + mid_url + index
url1 = preurl + end_rul
resp = requests.get(url1, allow_redirects=False)
name = ch + mid_url + index + end_rul
if resp.status_code != 200:
url2 = preurl + alt_url + end_rul
# print(url2)
resp = requests.get(url2, allow_redirects=False)
name = ch + mid_url + index + alt_url + end_rul
with open(name, 'w') as fb:
fb.write(resp.content)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lizhen_hbu/stock_selection.git
git@gitee.com:lizhen_hbu/stock_selection.git
lizhen_hbu
stock_selection
stock_selection
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385