日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

知乎每日精选python阅读脚本

發布時間:2023/12/14 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 知乎每日精选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阅读脚本的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。