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

python抓取網(wǎng)頁圖片示例(python爬蟲)

 更新時間:2014年04月27日 10:45:33   作者:  
這篇文章主要介紹了python抓取網(wǎng)頁圖片示例(python爬蟲),需要的朋友可以參考下

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

#-*- encoding: utf-8 -*-
'''
Created on 2014-4-24

@author: Leon Wong
'''

import urllib2
import urllib
import re
import time
import os
import uuid

#獲取二級頁面url
def findUrl2(html):
    re1 = r'http://tuchong.com/\d+/\d+/|http://\w+(?<!photos).tuchong.com/\d+/'
    url2list = re.findall(re1,html)
    url2lstfltr = list(set(url2list))
    url2lstfltr.sort(key=url2list.index)
    #print url2lstfltr
    return url2lstfltr

#獲取html文本
def getHtml(url):
    html = urllib2.urlopen(url).read().decode('utf-8')#解碼為utf-8
    return html

#下載圖片到本地
def download(html_page , pageNo):  
    #定義文件夾的名字
    x = time.localtime(time.time())
    foldername = str(x.__getattribute__("tm_year"))+"-"+str(x.__getattribute__("tm_mon"))+"-"+str(x.__getattribute__("tm_mday"))
    re2=r'http://photos.tuchong.com/.+/f/.+\.jpg'
    imglist=re.findall(re2,html_page)
    print imglist
    download_img=None
    for imgurl in imglist:
        picpath = 'D:\\TuChong\\%s\\%s'  % (foldername,str(pageNo))
        filename = str(uuid.uuid1())
        if not os.path.exists(picpath):
            os.makedirs(picpath)              
        target = picpath+"\\%s.jpg" % filename
        print "The photos location is:"+target
        download_img = urllib.urlretrieve(imgurl, target)#將圖片下載到指定路徑中
        time.sleep(1)
        print(imgurl)
    return download_img


# def callback(blocknum, blocksize, totalsize):
#     '''回調(diào)函數(shù)
#     @blocknum: 已經(jīng)下載的數(shù)據(jù)塊
#     @blocksize: 數(shù)據(jù)塊的大小
#     @totalsize: 遠(yuǎn)程文件的大小
#     '''
#     print str(blocknum),str(blocksize),str(totalsize)
#     if blocknum * blocksize >= totalsize:
#         print '下載完成'

def quitit():
    print "Bye!"
    exit(0)
   

if __name__ == '__main__':
    print '''            *****************************************
            **    Welcome to Spider for TUCHONG    **
            **      Created on 2014-4-24           **
            **      @author: Leon Wong             **
            *****************************************'''
    pageNo = raw_input("Input the page number you want to scratch (1-100),please input 'quit' if you want to quit>")
    while not pageNo.isdigit() or int(pageNo) > 100 :
        if pageNo == 'quit':quitit()
        print "Param is invalid , please try again."
        pageNo = raw_input("Input the page number you want to scratch >")

    #針對圖蟲人像模塊來爬取
    html = getHtml("http://tuchong.com/tags/%E4%BA%BA%E5%83%8F/?page="+str(pageNo))

    detllst = findUrl2(html)
    for detail in detllst:
        html2 = getHtml(detail)
        download(html2,pageNo)
    print "Finished."

相關(guān)文章

  • 開源軟件包和環(huán)境管理系統(tǒng)Anaconda的安裝使用

    開源軟件包和環(huán)境管理系統(tǒng)Anaconda的安裝使用

    Anaconda是一個用于科學(xué)計(jì)算的Python發(fā)行版,支持 Linux, Mac, Windows系統(tǒng),提供了包管理與環(huán)境管理的功能,可以很方便地解決多版本python并存、切換以及各種第三方包安裝問題。
    2017-09-09
  • 使用tensorflow實(shí)現(xiàn)AlexNet

    使用tensorflow實(shí)現(xiàn)AlexNet

    這篇文章主要為大家詳細(xì)介紹了使用tensorflow實(shí)現(xiàn)AlexNet,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • Python用HBuilder創(chuàng)建交流社區(qū)APP

    Python用HBuilder創(chuàng)建交流社區(qū)APP

    這篇文章主要講解Python使用HBuilder創(chuàng)建交流社區(qū)APP,使用HBuilder做一個簡單的社區(qū)瀏覽界面,下面文章附有詳細(xì)的代碼,需要的朋友可以參考一下
    2021-11-11
  • python實(shí)現(xiàn)上傳文件到linux指定目錄的方法

    python實(shí)現(xiàn)上傳文件到linux指定目錄的方法

    這篇文章主要介紹了python實(shí)現(xiàn)上傳文件到linux指定目錄的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-01-01
  • 基于Flask實(shí)現(xiàn)文件上傳七牛云中并下載

    基于Flask實(shí)現(xiàn)文件上傳七牛云中并下載

    文件上傳是Web應(yīng)用中常見的功能之一,而七牛云則提供了強(qiáng)大的云存儲服務(wù),本文我們將學(xué)習(xí)如何在Flask應(yīng)用中實(shí)現(xiàn)文件上傳,并將上傳的文件保存到七牛云,感興趣的可以學(xué)習(xí)一下
    2023-10-10
  • python中根據(jù)字符串調(diào)用函數(shù)的實(shí)現(xiàn)方法

    python中根據(jù)字符串調(diào)用函數(shù)的實(shí)現(xiàn)方法

    下面小編就為大家?guī)硪黄猵ython中根據(jù)字符串調(diào)用函數(shù)的實(shí)現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考,一起跟隨小編過來看看吧
    2016-06-06
  • Python讀寫ini文件的方法

    Python讀寫ini文件的方法

    這篇文章主要介紹了Python讀寫ini文件的方法,實(shí)例分析了Python針對ini配置文件的讀寫及修改等操作技巧,需要的朋友可以參考下
    2015-05-05
  • Matplotlib自定義坐標(biāo)軸刻度的實(shí)現(xiàn)示例

    Matplotlib自定義坐標(biāo)軸刻度的實(shí)現(xiàn)示例

    這篇文章主要介紹了Matplotlib自定義坐標(biāo)軸刻度的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-06-06
  • Python3中FuzzyWuzzy庫實(shí)例用法

    Python3中FuzzyWuzzy庫實(shí)例用法

    在本篇文章中小編給各位整理了關(guān)于Python3z中FuzzyWuzzy庫實(shí)例用法及相關(guān)代碼,有興趣的朋友們可以參考下。
    2020-11-11
  • Python使用while循環(huán)花式打印乘法表

    Python使用while循環(huán)花式打印乘法表

    今天小編就為大家分享一篇關(guān)于Python使用while循環(huán)花式打印乘法表,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-01-01

最新評論

华容县| 石嘴山市| 丰城市| 磐安县| 柯坪县| 德令哈市| 浏阳市| 苗栗县| 招远市| 吉安市| 银川市| 屏东市| 怀集县| 余江县| 屏山县| 城步| 阿克苏市| 建平县| 天长市| 左权县| 明溪县| 靖江市| 文山县| 行唐县| 和静县| 全州县| 永胜县| 济宁市| 顺昌县| 兴国县| 涞源县| 贡嘎县| 加查县| 金坛市| 溧水县| 盖州市| 大埔区| 晴隆县| 衡阳县| 泗洪县| 邛崃市|