Python下載懶人圖庫JavaScript特效
這是一個(gè)簡單的Python腳本,主要從懶人圖庫下載JavaScript特效模板,在腳本中使用了gevent這個(gè)第三方庫,使用的時(shí)候需要先安裝。
#!/usr/bin/python # -*- coding: utf-8 -*- import urllib,os,sys import gevent,re from gevent import monkey from bs4 import BeautifulSoup gevent.monkey.patch_socket() ''' Description:Python 爬蟲抓取懶人圖庫的JS腳本模板 Author:admin Create-Date:2015-05-25 Version:1.0 ''' HTTP_URL = 'http://www.lanrentuku.com%s' DOWNLOAD_URL = HTTP_URL[:-2] + '/js/d%szip' reg=r'\d{1,}\.+' def encode(text): return text.encode("utf8") def createDirectory(curPath): myPath = os.path.join(getSubDirectory(), u'JS代碼模板') if not os.path.exists(myPath): os.mkdir(myPath) return os.path.join(myPath, curPath) def getSubDirectory(): return os.getcwd() def schedule(a, b, c): per = 100.0 * a * b / c if per > 100 : per = 100 sys.stdout.write('%.1f%%\r' % per) sys.stdout.flush() def geturllist(url): url_list = {} html = urllib.urlopen(url) content = html.read() html.close() # 用BeautifulSoup解析 decodeHtml = BeautifulSoup(content) try: aTags = decodeHtml.find_all('div', {'class':'list-pngjs'})[0].find_all('a') except IndexError, e: print e aTags = None # 獲取鏈接地址和標(biāo)題 if aTags is not None: for a_tag in aTags: url_list[HTTP_URL % a_tag.get('href')] = a_tag.get_text() return url_list def download(down_url): try: m=re.search(reg,down_url[0]) name = DOWNLOAD_URL % m.group(0) urllib.urlretrieve(name,createDirectory(down_url[1] + name[-4:]),schedule) except Exception, e: print e.message def getpageurl(xUrl): # 進(jìn)行列表頁循環(huán) return [xUrl % page for page in xrange(1,49)] if __name__ == '__main__': jobs = [] pageurl = getpageurl('http://www.lanrentuku.com/js/p%s.html') # 爬取所有鏈接 for i in pageurl: for k in geturllist(i).items(): jobs.append(gevent.spawn(download, k)) gevent.joinall(jobs)
以上所述就是本文的全部內(nèi)容了,希望大家能夠喜歡。
- python通過urllib2爬網(wǎng)頁上種子下載示例
- python支持?jǐn)帱c(diǎn)續(xù)傳的多線程下載示例
- Python實(shí)現(xiàn)股市信息下載的方法
- python實(shí)現(xiàn)批量下載新浪博客的方法
- python操作ssh實(shí)現(xiàn)服務(wù)器日志下載的方法
- python基于urllib實(shí)現(xiàn)按照百度音樂分類下載mp3的方法
- Python實(shí)現(xiàn)豆瓣圖片下載的方法
- Python實(shí)現(xiàn)批量下載文件
- Python使用urllib2模塊實(shí)現(xiàn)斷點(diǎn)續(xù)傳下載的方法
相關(guān)文章
在python中實(shí)現(xiàn)將一張圖片剪切成四份的方法
今天小編就為大家分享一篇在python中實(shí)現(xiàn)將一張圖片剪切成四份的方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12Python常用數(shù)據(jù)庫接口sqlite3和MySQLdb學(xué)習(xí)指南
在本章節(jié)中,我們將學(xué)習(xí) Python 中常用的數(shù)據(jù)庫接口,包括 sqlite3用于SQLite數(shù)據(jù)庫和MySQLdb用于 MySQL 數(shù)據(jù)庫,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06如何利用Opencv實(shí)現(xiàn)圖像的加密解密
一般情況下,圖像的加密和解密過程是通過按位異或運(yùn)算實(shí)現(xiàn)的,下面這篇文章主要給大家介紹了關(guān)于如何利用Opencv實(shí)現(xiàn)圖像加密解密的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2021-10-10python批量檢查兩個(gè)對應(yīng)的txt文件的行數(shù)是否一致的實(shí)例代碼
這篇文章主要介紹了python批量檢查兩個(gè)對應(yīng)的txt文件的行數(shù)是否一致,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10python3.7.3版本和django2.2.3版本是否可以兼容
在本篇文章里小編給大家整理的是一篇關(guān)于python3.7.3版本和django2.2.3版本是否可以兼容的相關(guān)知識點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)下。2020-09-09Jupyter Notebook的連接密碼 token查詢方式
這篇文章主要介紹了Jupyter Notebook的連接密碼 token查詢方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04關(guān)于tf.matmul() 和tf.multiply() 的區(qū)別說明
這篇文章主要介紹了關(guān)于tf.matmul() 和tf.multiply() 的區(qū)別說明,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06python中實(shí)現(xiàn)精確的浮點(diǎn)數(shù)運(yùn)算詳解
計(jì)算機(jī)智能處理可數(shù)集合的運(yùn)算,但是全體實(shí)數(shù)是不可數(shù)的,所以計(jì)算機(jī)只能用一些奇怪的方法來擬合他,于是就產(chǎn)生了浮點(diǎn)數(shù)。下面這篇文章主要給大家介紹了關(guān)于python中實(shí)現(xiàn)精確浮點(diǎn)數(shù)運(yùn)算的相關(guān)資料,需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2017-11-11