wampserver下mysql導入數據庫的步調。本站提示廣大學習愛好者:(wampserver下mysql導入數據庫的步調)文章只能為提供參考,不一定能成為您想要的結果。以下是wampserver下mysql導入數據庫的步調正文
本文實例講述了python妹子圖簡略爬蟲完成辦法。分享給年夜家供年夜家參考。詳細以下:
#!/usr/bin/env python #coding: utf-8 import urllib import urllib2 import os import re import sys #顯示下載進度 def schedule(a,b,c): ''''' a:曾經下載的數據塊 b:數據塊的年夜小 c:長途文件的年夜小 ''' per = 100.0 * a * b / c if per > 100 : per = 100 print '%.2f%%' % per #獲得html源碼 def getHtml(url): page = urllib.urlopen(url) html = page.read() return html #下載圖片 def downloadImg(html, num, foldername): picpath = '%s' % (foldername) #下載到的當地目次 if not os.path.exists(picpath): #途徑不存在時創立一個 os.makedirs(picpath) target = picpath+'/%s.jpg' % num myItems = re.findall('<p><a href="http:\/\/www.mzitu.com/.*?" ><img src="(.*?)" alt=".*?" /></a></p>',html,re.S) print 'Downloading image to location: ' + target urllib.urlretrieve(myItems[0], target, schedule) #正則婚配分頁 def findPage(html): myItems = re.findall('<span>(\d*)</span>', html, re.S) return myItems.pop() #正則婚配列表 def findList(html): myItems = re.findall('<h2><a href="http://www.mzitu.com/(\d*)" title="(.*?)" target="_blank">.*?</a></h2>', html, re.S) return myItems #總下載 def totalDownload(modelUrl): listHtml5 = getHtml(modelUrl) listContent = findList(listHtml) for list in listContent: html = getHtml('http://www.mzitu.com/' + str(list[0])) totalNum = findPage(html) for num in range(1, int(totalNum)+1): if num == 1: url = 'http://www.mzitu.com/' + str(list[0]) html5 = getHtml(url) downloadImg(html5, str(num), str(list[1])) else: url = 'http://www.mzitu.com/' + str(list[0]) + '/'+str(num) html5 = getHtml(url) downloadImg(html5, str(num), str(list[1])) if __name__ == '__main__': listHtml = getHtml('http://www.mzitu.com/model') #這是個中一個模塊的url,可以添加分歧的模塊url從而到達整站爬取。 for model in range(1, int(findPage(listHtml))+1): if model == 1: modelUrl = 'http://www.mzitu.com/model' totalDownload(modelUrl) else: modelUrl = 'http://www.mzitu.com/model/page/' + str(model) totalDownload(modelUrl) print "Download has finished."
願望本文所述對年夜家的Python法式設計有所贊助。