item in enumerate(itemBox):#遍历itemBox, attrs={'class': 'itemTxt'})#因为只有一个, li_list_split in enumerate(thread_count):#拆分了多少个list就创建多少个线程thread = myThread(li_list_split, split_dds, 本帖最后由 三木猿 于 2020-9-3 13:33 编辑 看来大家很喜欢,记得点免费评分呦,item是内容itemTxt = item.find('div', name, '')if not os.path.exists(path):os.makedirs(path)while True:li_a_href_replace = li_a_hrefif i != 0:li_a_href_replace = li_a_href.replace('.', self.name)print(退出线程: + self.num)def split_list(ls, attrs={'id': 'chapter-list-1'})#获取到ulbook_name = chapter_html_list.find('h1',所以输入的序号减一获取对应书的url, num):threading.Thread.__init__(self)self.name = nameself.split_dds = split_ddsself.num = numdef run(self):print(开始线程: + self.num)save_img(self.split_dds, each):list = []eachExact = float(each)groupCount = int(len(ls) // each)groupCountExact = math.ceil(len(ls) / eachExact)start = 0for i in xrange(each):if i == each - 1 groupCount groupCountExact: # 假如有余数, book_name。
'wb').write(get_document(img_src))#保存到d:/SanMu/书名/章节名/0.jpgi += 1def download_img(html):chapter_url_list=[]soup = BeautifulSoup(html,index是当前项list的下标, 'lxml')#BeautifulSoup和request搭配使用更佳呦itemBox = soup.find_all('div', book_name):for num in range(len(li_list_split)):#遍历li=li_list_split[num]li_a_href = li.find('a')['href']#注意这里获取到的url是不完整的/manhua/buhuochongwuniangdezhengquefangfa/1000845.htmli = 0path = d:/SanMu/+book_name+'http://www.52pojie.cn/'+li.text.replace('\n', timeimport osimport requestsfrom bs4 import BeautifulSoupfrom urllib3.connectionpool import xrangefrom tqdm import tqdmclass myThread (threading.Thread):def __init__(self,再发个多线程版的, 'lxml')#因为打印的序号和list的索引是相差1的, str(num))thread_list.append(thread)for thread in thread_list:thread.start()for thread in thread_list:thread.join()while 1:breakdownload_img(get_document(https://m.gufengmh8.com/search/?keywords=+str(input(搜索漫画:)))) , ('-' + str(i) + '.'))chapter_html = BeautifulSoup(get_document('https://m.gufengmh8.com' + li_a_href_replace),将剩余的所有元素加入到最后一个分组list.append(ls[start:len(ls)])else:list.append(ls[start:start + groupCount])start = start + groupCountreturn listdef get_document(url):# print(url)try:get = requests.get(url)data = get.contentget.close()except:time.sleep(3)try:get = requests.get(url)data = get.contentget.close()except:time.sleep(3)get = requests.get(url)data = get.contentget.close()return datadef save_img(li_list_split, attrs={'class': 'chapter-content'})img_src = chapter_content.find('img')['src']open(path+'http://www.52pojie.cn/'+str(i)+'.jpg'。
再根据url获取到目录页面ul = chapter_html_list.find('ul'。
漫画多少章就启多少个线程的那种(另外多线程不是越多越好,for num,所以itemBox中只有一个itemTxt所以这次我们用finda = itemTxt.find('a', len(li_list))#多少章就启多少个线程len(li_list)可以改成固定的线程数。
有些网站会有保护措施。
'lxml')chapter_content = chapter_html.find('div', attrs={'class': 'title'})chapter_url = a['href']chapter_url_list.append(chapter_url)#把所有书的url存起来print(str(index+1)+'.'+a.text)number = int(input('请输入漫画序号'))chapter_html_list = BeautifulSoup(get_document(chapter_url_list[number-1]), attrs={'class': 'itemBox'})#find_all返回的是一个listfor index。
attrs={'class': 'title'}).text#获取到ulli_list = ul.find_all('li')#获取其中所有lithread_list = []thread_count = split_list(li_list,。
太多线程同时请求可能会被封ip呦) [Python] 纯文本查看 复制代码 import mathimport threadingimport sys, attrs={'class': 'chapter-content'})img_src = chapter_content.find('img')['src']if img_src.__eq__('https://res.xiaoqinre.com/images/default/cover.png'):breakchapter_content = chapter_html.find('div'。
