日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

喜欢看漫画的小伙伴就不要错过啦,python批量爬取动漫免费看

發(fā)布時(shí)間:2024/1/8 python 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 喜欢看漫画的小伙伴就不要错过啦,python批量爬取动漫免费看 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

實(shí)現(xiàn)效果


運(yùn)行環(huán)境

  • IDE VS2019

  • Python3.7

  • Chrome、ChromeDriver

  • Chrome和ChromeDriver的版本需要相互對應(yīng)

先上代碼,代碼非常簡短,包含空行也才50行,多虧了python強(qiáng)大的庫

import os import time import requests from selenium import webdriver from lxml import etree ''' python學(xué)習(xí)交流群:1136201545更多學(xué)習(xí)資料可以加群獲取 ''' def getChapterUrl(url):headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36"}part_url = "http://ac.qq.com"res = requests.get(url, headers=headers)html=res.content.decode()el = etree.HTML(html)li_list = el.xpath('//*[@id="chapter"]/div[2]/ol[1]/li')for li in li_list:for p in li.xpath("./p"):for span in p.xpath("./span[@class='works-chapter-item']"):item = {}list_title = span.xpath("./a/@title")[0].replace(' ', '').split(':')if list_title[1].startswith(('第', '序')):getChapterFile(part_url + span.xpath("./a/@href")[0], list_title[0],list_title[1])def getChapterFile(url,path1,path2):#path = os.path.join(path)#漫畫名稱目錄path=os.path.join(path1)if not os.path.exists(path):os.mkdir(path)#章節(jié)目錄path=path+'\\'+path2if not os.path.exists(path):os.mkdir(path)chrome=webdriver.Chrome()#"http://ac.qq.com/ComicView/index/id/505435/cid/2"chrome.get(url)time.sleep(4)imgs = chrome.find_elements_by_xpath("//div[@id='mainView']/ul[@id='comicContain']//img")for i in range(0, len(imgs)):js="document.getElementById('mainView').scrollTop="+str((i) * 1280)chrome.execute_script(js)time.sleep(3)print(imgs[i].get_attribute("src"))with open(path+'\\'+str(i)+'.png', 'wb') as f:f.write(requests.get(imgs[i].get_attribute("src")).content)chrome.close() print('下載完成') if __name__ == '__main__':getChapterUrl('http://ac.qq.com/Comic/ComicInfo/id/505435')

簡單解釋

輸入一個(gè)漫畫的url即可爬取該漫畫所有的章節(jié),由于是模擬用戶爬取的,所以速度方面有點(diǎn)慢,我試了下爬取銀魂前70章,用了1個(gè)半小時(shí),代碼中的sleep可以適當(dāng)簡短點(diǎn)已加快爬取的速度

付費(fèi)的漫畫是沒有辦法爬取的

總結(jié)

以上是生活随笔為你收集整理的喜欢看漫画的小伙伴就不要错过啦,python批量爬取动漫免费看的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。