當前位置:
首頁 >
Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe
發布時間:2025/4/16
45
豆豆
生活随笔
收集整理的這篇文章主要介紹了
Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
代碼如下:
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 # 設置電子書元數據 9 #/ 10 title = 'Runoob Python 2 教程' # 電子書名 11 description = 'Python是一種解釋型、面向對象、動態數據類型的高級程序設計語言。Python由Guido van Rossum于1989年底發明,第一個公開發行版發行于1991年。像Perl語言一樣, Python 源代碼同樣遵循 GPL(GNU General Public License)協議。本教程主要針對Python 2.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 # 抓取頁面內容設置 19 #/ 20 #keep_only_tags = [{ 'class': 'example' }] # 僅保留指定選擇器包含的內容 21 no_stylesheets = True # 去除 CSS 樣式 22 remove_javascript = True # 去除 JavaScript 腳本 23 # oldest_article = 7 24 max_articles_per_feed = 999 # 抓取文章數量 25 delay = 5 # 抓取資源間隔時間 26 auto_cleanup = True 27 #/ 28 # 頁面內容解析方法 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 = [] # 定義文章資源數組 35 for link in links: # 循環處理所有文章鏈接 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) # 累加到數組中 43 ans = [(self.title,articles)] # 組成最終的數據結構 44 return ans # 返回可供 Calibre 轉換的數據結構?
轉載于:https://www.cnblogs.com/mcgill0217/p/10296052.html
總結
以上是生活随笔為你收集整理的Calibre 3.38.1 下载 Runoob 网站中的《Python 2 教程》的 Recipe的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: vue双向数据绑定原理分析--Mr.Em
- 下一篇: python + MySql 基本操作