Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe
生活随笔
收集整理的這篇文章主要介紹了
Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
代碼如下:
1 #!/usr/bin/env python2 2 # vim:fileencoding=utf-8 3 from __future__ import unicode_literals, division, absolute_import, print_function 4 from calibre.web.feeds.news import BasicNewsRecipe 5 6 class AdvancedUserRecipe1547983886(BasicNewsRecipe): # 繼承 BasicNewsRecipe 類的新類名 7 #/ 8 # 設(shè)置電子書元數(shù)據(jù) 9 #/ 10 title = 'Runoob Python 2 教程' # 電子書名 11 description = 'Python是一種解釋型、面向?qū)ο蟆討B(tài)數(shù)據(jù)類型的高級程序設(shè)計語言。Python由Guido van Rossum于1989年底發(fā)明,第一個公開發(fā)行版發(fā)行于1991年。像Perl語言一樣, Python 源代碼同樣遵循 GPL(GNU General Public License)協(xié)議。本教程主要針對Python 2.x版本的學(xué)習(xí),如果你使用的是Python 3.x版本請移步至Python 3.X版本的教程。' # 電子書簡介 12 cover_url = 'http://www.runoob.com/wp-content/uploads/2013/11/python.jpg' # 電子書封面 13 # masthead_url = '' # 頁頭圖片 14 __author__ = 'Runoob' # 作者 15 language = 'zh' # 語言 16 encoding = 'utf-8' # 編碼 17 #/ 18 # 抓取頁面內(nèi)容設(shè)置 19 #/ 20 #keep_only_tags = [{ 'class': 'example' }] # 僅保留指定選擇器包含的內(nèi)容 21 no_stylesheets = True # 去除 CSS 樣式 22 remove_javascript = True # 去除 JavaScript 腳本 23 # oldest_article = 7 24 max_articles_per_feed = 999 # 抓取文章數(shù)量 25 delay = 5 # 抓取資源間隔時間 26 auto_cleanup = True 27 #/ 28 # 頁面內(nèi)容解析方法 29 #/ 30 def parse_index(self): 31 site = 'http://www.runoob.com/python/python-tutorial.html' # 頁面列表頁 32 soup = self.index_to_soup(site) # 解析列表返回 BeautifulSoup 對象 33 links = soup.findAll('a', {'target': '_top'}) # 獲取所有文章的鏈接地址 34 articles = [] # 定義文章資源數(shù)組 35 for link in links: # 循環(huán)處理所有文章鏈接 36 title = link.contents[0].strip() # 提取文章標題 37 print(title) 38 print(link) 39 url = site + link['href'] # 提取文章鏈接 40 print(u'%s'%(url)) 41 a ={'title':title,'url':url} # 組合標題和鏈接 42 articles.append(a) # 累加到數(shù)組中 43 ans = [(self.title,articles)] # 組成最終的數(shù)據(jù)結(jié)構(gòu) 44 return ans # 返回可供 Calibre 轉(zhuǎn)換的數(shù)據(jù)結(jié)構(gòu)?
轉(zhuǎn)載于:https://www.cnblogs.com/mcgill0217/p/10296052.html
總結(jié)
以上是生活随笔為你收集整理的Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue双向数据绑定原理分析--Mr.Em
- 下一篇: Flash和滚动字幕