#coding=utf-8
import sys
import time
import os
import json
import requests
import math
from sys import getsizeof
reload(sys)
sys.setdefaultencoding('utf-8')
global_data = 0
isbreak = False
def home():
url_02 = "https://prod-api.ishuhui.com/ver/ea149533/setting/page?page=/&.json"
ir = requests.get(url_02)
shuhui_load_dict = getdown_id()
load_id_list = []
book_json = json.loads(ir.content)
# 喵的 改版版結(jié)構(gòu)比原來(lái)更加優(yōu)秀了,這1,2,3,啊什么鬼啊 book_json['data'][1]["data"][1]["data"][1]["viewData"]
manhua_data_list = book_json['data'][1]["data"][1]["data"][1]["viewData"]
for key in reversed(manhua_data_list) :
if isbreak:
break
# 章節(jié)id 漫畫(huà)名稱(chēng) 最新章節(jié)數(shù) 章節(jié)名稱(chēng)
chapater_id = key['id']
chapater_book = key['title']
chapater_number = key['minorTitle']
chapater_title = key['desc']
if shuhui_load_dict.has_key(str(chapater_id)):
continue
url_04 = " https://prod-api.ishuhui.com/comics/detail?id=%s"%chapater_id
ir = requests.get(url_04)
decodejson = json.loads(ir.content)
#這里分兩種寫(xiě)法 自己服務(wù)器上能用多線(xiàn)程 新浪云上沒(méi)試驗(yàn)過(guò)
load_picture(decodejson["data"]["contentImg"],chapater_book,chapater_title)
load_id_list.append(chapater_id)
manhua_data_dict = {}
for key in manhua_data_list:
manhua_data_dict[key['id']] = [key['title'],key['desc']]
writedown_id(shuhui_load_dict,manhua_data_dict,load_id_list)
def load_picture(url_lists,book_text,title):
global global_data
global isbreak
#url_lists 包括路徑和漫畫(huà)的序號(hào)
picture_dict = url_lists
load_book_text = book_text
load_title = title
#這里在新浪云要變換下
serchfile = load_book_text + "\\" + load_title
num = 0
print "now loading:" + serchfile
mkdir(load_book_text)
mkdir(load_book_text + "\\" + load_title)
time_over = time.strftime('%y-%m',time.localtime(time.time()))
mkdir(time_over)
mkdir(time_over + "\\" + serchfile)
monthfile = time_over + "\\" + serchfile
bar = ProgressBar(total = len(picture_dict))
for key in picture_dict:
#wait_url(time.time())
#load_url = "http://pic01.ishuhui.com" + picture_dict[key].replace('/upload',"")
load_url = key["url"]
#print load_url
ir = requests.get(load_url,timeout=10)
global_data = global_data + int(sys.getsizeof(ir.content))
sz = open(r'%s\%s.jpg'%(serchfile,key["name"]) , 'wb').write(ir.content)
kz = open(r'%s\%s.jpg'%(monthfile,key["name"]) , 'wb').write(ir.content)
#print num
num = num + 1
bar.move()
bar.log()
print load_title + "下載完成"
if global_data > 1024*1024*12:
print "data > 12M"
isbreak = True
def mkdir(path):
# 判斷路徑是否存在
# 存在 True
# 不存在 False
print path
isExists=os.path.exists(path)
# 判斷結(jié)果
if not isExists:
# 如果不存在則創(chuàng)建目錄
#print path+' 創(chuàng)建成功'
# 創(chuàng)建目錄操作函數(shù)
os.makedirs(path)
return True
else:
# 如果目錄存在則不創(chuàng)建节槐,并提示目錄已存在
#print path+' 目錄已存在'
return False
class ProgressBar:
def __init__(self, count = 0, total = 0, width = 50):
self.count = count
self.total = total
self.width = width
def move(self):
self.count += 1
def log(self):
sys.stdout.write(' ' * (self.width + 9) + '\r')
sys.stdout.flush()
#print s
progress = self.width * self.count / self.total
sys.stdout.write('{0:3}/{1:3}: '.format(self.count, self.total))
sys.stdout.write('#' * progress + '-' * (self.width - progress) + '\r')
if progress == self.width:
sys.stdout.write('\n')
sys.stdout.flush()
def getdown_id():
path_file = "download_id_list.txt"
download_id_list = {}
if os.path.exists(path_file):
file = open(path_file,'r')
for line in file.readlines():
# 讀取文檔內(nèi)容哺眯,循環(huán)存入漫畫(huà)id
download_id_list[line.strip().split('\t')[0]] = [line.strip().split('\t')[1],line.strip().split('\t')[2]]
else:
file = open(path_file,'w')
file.close()
return download_id_list
def writedown_id(shuhui_load_dict,manhua_data_dict,load_id_list):
for key in list(shuhui_load_dict.keys()):
if manhua_data_dict.has_key(int(key)):
continue
else:
del shuhui_load_dict[key]
for key in load_id_list:
shuhui_load_dict[key] = manhua_data_dict[key]
with open("download_id_list.txt",'w') as file:
file.writelines(dict_to_text(shuhui_load_dict))
def dict_to_text(data_dict):
outstr = ""
for key in data_dict:
outstr = outstr + str(key) + '\t' + str(data_dict[key][0]) + '\t' + str(data_dict[key][1]) + '\n'
return outstr
改版后鼠繪爬蟲(chóng)代碼
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)泞边,“玉大人该押,你說(shuō)我怎么就攤上這事≌笱瑁” “怎么了沈善?”我有些...
- 文/不壞的土叔 我叫張陵,是天一觀(guān)的道長(zhǎng)椭蹄。 經(jīng)常有香客問(wèn)我闻牡,道長(zhǎng),這世上最難降的妖魔是什么绳矩? 我笑而不...
- 正文 為了忘掉前任罩润,我火速辦了婚禮,結(jié)果婚禮上翼馆,老公的妹妹穿的比我還像新娘割以。我一直安慰自己,他們只是感情好应媚,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布严沥。 她就那樣靜靜地躺著,像睡著了一般中姜。 火紅的嫁衣襯著肌膚如雪消玄。 梳的紋絲不亂的頭發(fā)上,一...
- 那天丢胚,我揣著相機(jī)與錄音翩瓜,去河邊找鬼。 笑死携龟,一個(gè)胖子當(dāng)著我的面吹牛兔跌,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播峡蟋,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼坟桅,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來(lái)了蕊蝗?” 一聲冷哼從身側(cè)響起仅乓,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎匿又,沒(méi)想到半個(gè)月后方灾,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年裕偿,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了洞慎。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站重父,受9級(jí)特大地震影響花椭,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜房午,卻給世界環(huán)境...
- 文/蒙蒙 一矿辽、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧郭厌,春花似錦袋倔、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至扇售,卻和暖如春前塔,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背缘眶。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像慌洪,于是被迫代替她去往敵國(guó)和親顶燕。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 我放在新浪云上的小爬蟲(chóng)冈爹,每天定時(shí)訪(fǎng)問(wèn)鼠繪漫畫(huà)涌攻,如果有更新,就下載對(duì)應(yīng)的更新频伤,并保存起來(lái)恳谎,下面是詳細(xì)的代碼說(shuō)明,因?yàn)?..
- 本文內(nèi)容來(lái)自公眾號(hào):章魚(yú)哥筆記 (wixi38) 最終效果 1、參考的原始圖像因痛。 2婚苹、確保遵循臉部曲線(xiàn)和光線(xiàn)描繪出...
- 作為女性,我不乏陰柔之美鸵膏,因?yàn)橹两癫采阴r于他人爭(zhēng)斗,即使我是一名律師谭企。但是記憶里廓译,我卻和一只黃鼠狼動(dòng)起武來(lái),進(jìn)...
- WechatSogou [1]– 微信公眾號(hào)爬蟲(chóng)债查。 基于搜狗微信搜索的微信公眾號(hào)爬蟲(chóng)接口非区,可以擴(kuò)展成基于搜狗搜索的...