20200311_最新のクロールmzitu

 

 騒ぎ、直接コードで、python3.6:

インポート要求
BS4のインポートBeautifulSoupから
のインポートのOS 
インポート時。
輸入ランダム

#pipインストールBeautifulSoup4 -i https://pypi.douban.com/simple 
#pipリクエストをインストール-i https://pypi.douban.com/simple 

#HTTP请求头
Hostreferer = { 
    'リファラー':「のhttp: //www.mzitu.com ' 
    
    'アップグレード・安全でない-要求': '1'、
    'ユーザーエージェント':'のMozilla / 5.0(Windows NTの10.0; WOW64)のAppleWebKit / 537.36(ヤモリのようにKHTML、)クローム/ 69.0 .3497.100サファリ/ 537.36' 
} 

#此请求头リファラー破解盗图链接
Picreferer = { 
    # 'のUser-Agent': 'のMozilla / 4.0(互換; MSIE 6.0; Windows NTの5.1)'、 
    # 'のUser-Agent': 'のMozilla / 5.0(Windows NTの10.0; Win64の、のx64)のAppleWebKit / 537.36(ヤモリ様KHTML)クローム/ 73.0.3679.0サファリ/ 537.36' 、
    # 'リファラー': 'http://i.meizitu.net'、
    #https://www.mzitu.com/224497/3 
    'リファラー': 'http://www.mzitu.com'、
    「アップグレード-リクエスト、安全でない':' 1 ' 
    'User--エージェント':'のMozilla / 5.0(Windows NTの10.0; WOW64)のAppleWebKit / 537.36(KHTML、ヤモリ等)クローム/ 69.0.3497.100サファリ/ 537.36' 
} 
all_url =' HTTPS: //www.mzitu.com ' 
mzituホームall_url要求を開始#、格納されたHTMLデータを解析容易にするために戻ります
START_HTML = requests.get(all_url、ヘッダー= Hostreferer) 
    。IF 1 = N- :! 
        all_url + = all_url "/ページ/ "+ STR(N)+" / "。
  
スープ= BeautifulSoup(start_html.text、 "html.parser")#インデント
ページ=スープ。find_all(「A」、_ =クラスのページナンバー') 
シートの#最大数
max_page =ページ[-2]の.text 
範囲のN(1、INT(max_page)+ 1):
    パス= 'D:/ mzitu /' #存储路径
    all_url = 'https://www.mzitu.com' #重新赋值 
            ブレーク。
        ALT = imgs.get( 'ALT')。
        URL = href.get( 'のhref');
    印刷( '开始爬第%S页、网址是%s'は%(N、all_url))
    START_HTML = requests.get(all_url、ヘッダー= Hostreferer)。
    スープ= BeautifulSoup(start_html.text、 "html.parser")
#ALT = soup.find(ID = 'ピン')。find_all( ''、ターゲット= '_ブランク')。find_all( 'IMG'、=」class_が怠惰)Altキーを' ')(取得します。'; 
    href = soup.find(ID = 'ピン')find_all( ''、ターゲット= '_ブランク')。#根据ID找

    href属性のhrefのための:
        IMGS = href.find( 'IMG'、クラス_ = '遅延')。
        もしIMGS ==なし:
        start_html2 = requests.get(URL、ヘッダ= Hostreferer); 
        soup2 = BeautifulSoup(start_html2.text、 "html.parser")#缩进格式
        PAGE2 = soup2.find( 'DIV'、class_が=」pagenavi ')find_all(' '); 
        #プリント(PAGE2 [0]) 
        max_page2 = PAGE2 [-2]の.text。
        パス=パス+ alt.strip()(、 '' '?')交換してください。
        IF(os.path.exists(パス)):
            パス
            #プリント( '目录已存在')
        他:
            os.makedirs(パス)
        :Mの範囲内(1、INT(max_page2))のため

            time.sleep(random.randint (1,5)) 
            )#ALT = href.find( 'IMG'、クラス_ = '怠惰')( 'ALT'を取得します。 
            URL3 = URL + '/' + STR(M)+ '/' 
            プリント( '开始爬→%s'は%URL3)
            start_html3 = requests.get(URL3、ヘッダー= Hostreferer)。
            soup3 = BeautifulSoup(start_html3.text、 "html.parser")#缩进格式
            picSrc = soup3.find( 'DIV'、クラス_ = '主画像')。を見つける( '')。( 'IMG')を見つけます.get( 'SRC');#( 'SRC')を取得;#を取得します( 'SRCを');
            = requests.get HTML(picSrc、ヘッダー= Picreferer) 
抽出画像名
            FILE_NAME =パス+ '/' + picSrc.split(R&LT '/') - 1]; 
            画像保存# 
            F =オープン(FILE_NAME、 'WB ') 
            f.write(html.content)
            f.close()
            (%file_nameの '%sの画像の保存')印刷;

  

おすすめ

転載: www.cnblogs.com/wxylog/p/12460202.html