python爬蟲爬取美女圖片

來源:互聯網
上載者:User

標籤:爬蟲   python   

python 爬蟲爬取美女圖片


#coding=utf-8import urllibimport reimport osimport timeimport threadingdef getHtml(url):    page = urllib.urlopen(url)    html = page.read()    return htmldef getImgUrl(html,src):    srcre = re.compile(src)    srclist = re.findall(srcre,html)    return srclistdef getImgPage(html):    url = r'http://.*\.html'    urlre = re.compile(url)    urllist = re.findall(urlre,html)    return urllistdef downloadImg(url):    html = getHtml(url)    src = r'rel=.*\.jpg'    srclist = getImgUrl(html,src)    srclist2 = []    for srcs in srclist:        temp = srcs.replace("'",'"')        temp = temp.split('"')        srclist2.append(temp[1])    for srcurl in srclist2:        imgName = srcurl.replace(':','_')        imgName = imgName.replace('/','_')        print 'download pic %s .........' % srcurl        if os.path.isfile('pic/%s' % imgName):            continue        urllib.urlretrieve(srcurl,'pic/%s' % imgName)class MyThread(threading.Thread):    def __init__(self,urllist):        threading.Thread.__init__(self)        self.urllist = urllist    def run(self):        for u in self.urllist:            downloadImg(u)def main():    url = 'http://www.6188.net/'    html = getHtml(url)    urllist = getImgPage(html)    urllist2 = []    length = len(urllist) / 7    for i in range(1,8):        temp = urllist[(i-1)*length:i*length]        urllist2.append(temp)    for u in urllist2:        t = MyThread(u)        t.start()main()


python爬蟲爬取美女圖片

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.