最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python實(shí)現(xiàn)爬蟲下載漫畫示例

 更新時(shí)間:2014年02月16日 15:30:59   作者:  
本文主要介紹了python實(shí)現(xiàn)爬蟲下載漫畫的示例,對(duì)游俠網(wǎng)的漫畫資源進(jìn)行解析,下載其全部章節(jié)漫畫

復(fù)制代碼 代碼如下:

#!/usr/bin/python3.2
import os,socket
import urllib
import urllib.request,threading,time
import re,sys
global manhuaweb,weburl,floder,chapterbegin,currentthreadnum,threadcount,mutex,mutex2

weburl=''
floder=''
chapterbegin=0
currentthreadnum=0
threadcount=6


if len(sys.argv)>=3:
  weburl=sys.argv[1]
  floder=sys.argv[2]
else:
    print("usag: downloadmanhua weburl floder chapterbegin=0 threadnnum=6")
    sys.exit(0)
if len(sys.argv)>=4:
  chapterbegin=int(sys.argv[3])
if len(sys.argv)>=5:
  threadcount=(int)(sys.argv[4])

 

def jin(i,jinzhi):
        finalans=""
        answer=i%jinzhi
        i=int(i/jinzhi)
        if answer>9:
                finalans=finalans+chr(ord('a')+(answer-10))
        else:
                finalans=finalans+str(answer)
        if i!=0:
                finalans=jin(i,jinzhi)+finalans
        return finalans
def urlparse(p,a,c,k):
        d={}
        e=lambda c:     jin(c,36)
        if 1:
                while c:
                        c=c-1
                        if not k[c]:
                                d[jin(c,36)]=jin(c,36)
                        else:
                                d[jin(c,36)]=k[c]
                k=[lambda e:d[e]]
                e=lambda c:'\\w+'
                c=1
        newstr=""
        while c:
                c=c-1
                if k[c]:
                        for i in range(0,len(p)):
                                tempi=p[i]
                                tempi=ord(tempi)
                                if tempi>=ord('a') and tempi<=ord('f'):
                                        newstr+=d[chr(tempi)]
                                elif tempi>=ord('0') and tempi<=ord('9'):
                                        newstr+=d[chr(tempi)]
                                else:
                                        newstr+=chr(tempi)
        return newstr
def meispower(s):
        p=re.compile(r"(?=\}\().*",re.IGNORECASE)
        s=p.findall(s)
        s=s[0]
        s=s[0:(len(s)-19)]
        par=s.split(',')
        par[3]=par[3][1:len(par[3])]
        answer=par[3].split('|')
        chapterpath=urlparse(par[0],int(par[1]),int(par[2]),answer)
        allurl=re.findall('imgpath=[^;]*',chapterpath)[0]
        allurl=allurl[10:(len(allurl)-2)]
        return allurl
def pictofile(weburl,filename,loop=100):
        if loop<0:
                print('can\'t download the picture %s'%weburl)
                return
        loop=loop-1
        if os.path.exists(filename):
            return
        try:
                url=urllib.request.urlopen(weburl)
                data=url.read()
                if len(data)<2048:
                        url.close()
                        pictofile(weburl,filename,loop)
                else:
                        print('download from %s name is %s\n'%(weburl,filename))
                        myfile=open('%s'%filename,'wb')
                        myfile.write(data)
                        myfile.close()
                        url.close();
        except socket.timeout:
                print('timeout')
                pictofile(weburl,filename,loop)
        except Exception as e:
          print('error',e)
          pictofile(weburl,filename,loop)
        finally:
            pass
def downloadpic(url,loadpicdir,num):
    #download the all url picture to loadpicdir
    global currentthreadnum,mutex,mutex2
    mymode=re.compile(r'[0-9a-z.]*\Z')
    try:
                mutex2.acquire()
                os.chdir(loadpicdir)
                mutex2.release()
    except:
                print("can't open the floder %s will be create"%loadpicdir)
                try:
                    if(mutex2.locked()):
                        os.mkdir(loadpicdir)
                        os.chdir(loadpicdir)
                        mutex2.release()
                    print('create floder succeed')
                except:
                    print("can't create floder %s"%loadpicdir)
                    if(mutex.acquire()):
                        mutex.release()
                    quit(0)
    name=mymode.findall(url)
    filename='manhua'+name[0]
    pictofile(url,loadpicdir+'//'+str(num)+'-'+filename)
    mutex.acquire()
    currentthreadnum=currentthreadnum-1
    mutex.release()
def downloadchapter(url,loadpicdir,num,begin=0):
        global manhuaweb,threadcount,currentthreadnum,mutex
        print(manhuaweb+url)
        webdata=urllib.request.urlopen(manhuaweb+url).read()
        webdata=webdata.decode('UTF-8')
        chaptername=re.findall(r'<title>[^_]*',webdata)[0]
        chaptername=chaptername[7:len(chaptername)]
        webscrip=re.findall(r'eval.*[^<>]',webdata)
        chapterurl=meispower(webscrip[0]);
        chapterurl='http://mhimg.ali213.net'+chapterurl
        for i in range(begin,num):
                try:
                        while(currentthreadnum>=threadcount):
                                time.sleep(0.5)
                        mutex.acquire()
                        currentthreadnum=currentthreadnum+1
                        mutex.release()
                        threading.Thread(target=downloadpic,args=(r'%s%d.jpg'%(chapterurl,i),loadpicdir+chaptername,num)).start()
                except socket.error:
                        mutex.acquire()
                        i=i-1
                        currentthreadnum=currentthreadnum-1
                        mutex.release()
                except Exception as error:
                        print(error,'break')
                        print('download chapter %d of picture make a error'%i)
                        break
if __name__=='__main__':
        manhuaweb=r'http://manhua.ali213.net'
        socket.setdefaulttimeout(60.0)
        mutex=threading.Lock()
        mutex2=threading.Lock()

       
        webfile=urllib.request.urlopen(weburl)
        webdata=webfile.read();
        webdata=webdata.decode('UTF-8')
        meshmode=re.compile(r'<div class="detail_body_right_sec_con">.*</div>')
        meshdata=meshmode.findall(webdata)[0]
        indexmode=re.compile(r'([0-9]*頁(yè))')
        indexdata=indexmode.findall(meshdata)

        picurlmode=re.compile(r'/comic/[0-9/]*.html')
        picurldata=picurlmode.findall(meshdata)


        chapterlength=len(picurldata)
        nummode=re.compile(r'[\d]+')

        i=chapterbegin
        while i<chapterlength:
                manhuachapter=picurldata[chapterlength-i-1]
                downloadchapter(manhuachapter,floder,int(nummode.findall(indexdata[chapterlength-i-1])[0]))
                i=i+1

相關(guān)文章

  • Python實(shí)現(xiàn)將wav轉(zhuǎn)amr,并轉(zhuǎn)換成hex數(shù)組

    Python實(shí)現(xiàn)將wav轉(zhuǎn)amr,并轉(zhuǎn)換成hex數(shù)組

    這篇文章主要介紹了Python實(shí)現(xiàn)將wav轉(zhuǎn)amr,并轉(zhuǎn)換成hex數(shù)組方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Python第三方庫(kù)undetected_chromedriver的使用

    Python第三方庫(kù)undetected_chromedriver的使用

    這篇文章主要給大家介紹了關(guān)于Python第三方庫(kù)undetected_chromedriver的使用方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2023-01-01
  • 如何理解python中數(shù)字列表

    如何理解python中數(shù)字列表

    在本篇文章里小編給大家分享的是關(guān)于python中數(shù)字列表知識(shí)點(diǎn)詳解,有興趣的朋友們可以參考下。
    2020-05-05
  • python commands模塊的適用方式

    python commands模塊的適用方式

    這篇文章主要介紹了python commands模塊的適用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • python分?jǐn)?shù)表示方式和寫法

    python分?jǐn)?shù)表示方式和寫法

    在本篇文章里小編給大家整理的是關(guān)于python分?jǐn)?shù)怎么表示的相關(guān)知識(shí)點(diǎn)內(nèi)容,有需要的朋友們學(xué)習(xí)下吧。
    2019-06-06
  • 詳解PyCharm使用pyQT5進(jìn)行GUI開發(fā)的基本流程

    詳解PyCharm使用pyQT5進(jìn)行GUI開發(fā)的基本流程

    本文主要介紹了PyCharm使用pyQT5進(jìn)行GUI開發(fā)的基本流程,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 利用Python通過(guò)獲取剪切板數(shù)據(jù)實(shí)現(xiàn)百度劃詞搜索功能

    利用Python通過(guò)獲取剪切板數(shù)據(jù)實(shí)現(xiàn)百度劃詞搜索功能

    大家是不是嫌棄每次打開百度太麻煩?今天教大家利用Python通過(guò)獲取剪切板數(shù)據(jù)實(shí)現(xiàn)百度劃詞搜索功能,用程序直接打開網(wǎng)頁(yè),需要的朋友可以參考下
    2021-06-06
  • Python按條件刪除Excel表格數(shù)據(jù)的方法(示例詳解)

    Python按條件刪除Excel表格數(shù)據(jù)的方法(示例詳解)

    本文介紹基于Python語(yǔ)言,讀取Excel表格文件,基于我們給定的規(guī)則,對(duì)其中的數(shù)據(jù)加以篩選,將不在指定數(shù)據(jù)范圍內(nèi)的數(shù)據(jù)剔除,保留符合我們需要的數(shù)據(jù)的方法,感興趣的朋友跟隨小編一起看看吧
    2024-08-08
  • python 成功引入包但無(wú)法正常調(diào)用的解決

    python 成功引入包但無(wú)法正常調(diào)用的解決

    這篇文章主要介紹了python 成功引入包但無(wú)法正常調(diào)用的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-03-03
  • 詳解如何修改python中字典的鍵和值

    詳解如何修改python中字典的鍵和值

    這篇文章主要介紹了詳解如何修改python中字典的鍵和值,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09

最新評(píng)論

芦溪县| 吐鲁番市| 台前县| 万源市| 富裕县| 仙桃市| 原平市| 郯城县| 苏尼特右旗| 赤城县| 乌拉特后旗| 靖远县| 平利县| 台湾省| 红安县| 漯河市| 朔州市| 汝南县| 乌鲁木齐市| 卢龙县| 花莲市| 永安市| 镇康县| 银川市| 仙桃市| 兰西县| 中山市| 陵水| 宁德市| 梁河县| 娱乐| 昌邑市| 缙云县| 菏泽市| 汉阴县| 屏东市| 湘潭市| 凤城市| 辽源市| 台州市| 锡林郭勒盟|