我正试图找到一种方法来显示我正在为GUI工作的Google搜索/ RSS FEED的标题,网址和时间戳列表。我在尝试找到一种以可读的形式对结果进行排序的方法时遇到了很多麻烦。任何文章或指导,如果做什么将不胜感激!
from tkinter import *
import urllib.request
import feedparser
from pprint import pprint
search_term = ('') #search term for url
quoted_search_term = urllib.parse.quote(search_term)
def go():
text.delete(1.0, END) #delete text
rss_string = 'https://news.google.com/news/section?output=rss'.format (quoted_search_term)
parsed_rss_string = feedparser.parse(rss_string) #assigning variable for parsed feed
text.insert(1.0, parsed_rss_string) #insert text of parsed feed
browser_window = Tk() #tk window
browser_window.title('RSS Feed') #Window title
label = Label(browser_window, text= 'Search:')
entry = Entry(browser_window)
button = Button(browser_window, text='Go', command = go)#Go Button
text = Text(browser_window) #results box
label.pack(side=TOP) #Positioning of search title
entry.pack(side=TOP) #Positioning of search box
button.pack(side=TOP)#Positioning of go
text.pack(side= RIGHT) #Positioning of text
browser_window.mainloop()
答案 0 :(得分:0)
要美化字符串,请使用void sort(int values[], int n)
{
//create array of finite size (65536)
int countArray[INT_MAX] = {0};
//loop through unsorted values to increment countArray index for each occurrence
for(int i = 0; i < n; i++) {
countArray[ values[i] ] += 1;
}
//starting index for sortedValues[]
int sortedIndex = 0;
//loop through each index value of countArray
//j represents the value
for(int j = 0; j < INT_MAX; j++) {
//how many times does the index of countArray occur in values[]?
int c = countArray[j];
//only add index j as a value to sortedValues[] if it appears in values[]
while(c > 0) {
//append j to sortedValues[]
values[sortedIndex] = j;
//decrease the count of countArray[j] once value appended to sortedValues[]
c -= 1;
//move to next index of sortedValues[]
sortedIndex += 1;
}
}
}
:
pprint.pformat
注:
from pprint import pformat
...
def go():
...
parsed = feedparser.parse(rss_string)
prettified = pformat(parsed)
text.insert("1.0", prettified)
中没有占位符;没有效果https://news.google.com/news/section?output=rss
。更新仅显示发布日期,标题,网址,您需要从词典中获取这些条目:
str.format