知乎每日精选python阅读脚本
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                知乎每日精选python阅读脚本
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                好久沒寫程序了,話說自從決定進審協后,感覺學了這么長時間的coding算是有點浪費。找工作的時候挺想去做編程的,但由于種種原因還是簽了家鄉的單位。如果家鄉的IT行業能稍微好一點,我就會毫不猶豫地去寫代碼啦。
廢話少說。寫了一個python腳本來看知乎每日精選,不過在命令行下挺不方便的,現在極想找一個CLI框架,像使用telnet那樣方便地在命令行里跳轉。
下面是截圖:
 
一開始沒有使用BeautifulSoup處理文章,導致沒有換行,可讀性特別差,用了bs后可讀性好多了。
上代碼:
#! /usr/bin/python # coding = utf-8import feedparser from bs4 import BeautifulSoup# encode, change to your env encoding # usually 'my_encode' in linux, and 'gbk' in Windows my_encode = 'gbk'try:feed = feedparser.parse('http://www.zhihu.com/rss') except:print "Conencting to zhihu.com error. Exiting..."# print zhihu info print feed.feed.title.encode(my_encode) print feed.feed.subtitle.encode(my_encode) print '**********************************************'def print_list():# answer numberi = 0for item in feed.entries:print("%s\t%s\t%s\t%s\n" %("No.", "Question", "Replier", "Time"))print("%d\t%s\t%s\t%s\n" %(i, \item.title.encode(my_encode), \item.author.encode(my_encode), \item.published.encode(my_encode)))i = i + 1# user interacting while(1):print_list()an = raw_input("Please input the No. of answer to view detailed answer, input E to exit...")if int(an) <= len(feed.entries):print BeautifulSoup(feed.entries[int(an)].summary).prettify()an2 = raw_input("Input R to return list, Input E to exit...")if an2 == 'R' or an2 == 'r':continueelif an2 == 'E' or an2 == 'e':exit(1)elif an == 'E' or an == 'e':print "Exiting now..."exit(1)總結
以上是生活随笔為你收集整理的知乎每日精选python阅读脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Matlab图像显示
- 下一篇: Adobe Originals的可变字体
