import
tkinter
from
threading
import
Thread
from
tkinter
import
ttk, messagebox
from
requests
import
get
from
lxml
import
etree
import
webbrowser
HEADERS
=
{
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36'
}
def
gogo_start(item_url):
webbrowser.
open
(item_url)
def
app_info():
messagebox.showinfo(
'提示'
,
"本软件内所有新闻内容均来自:\n【今日热点:https://tophub.today】\n其内容未经证实不得肆意造谣!!!\n同意请确定/否则请关闭并删除本软件!"
)
class
SpinderMain(
object
):
def
__init__(
self
):
self
.all_url
=
{
'微博热搜'
:
'https://tophub.today/n/KqndgxeLl9'
,
'微信 ‧ 24h热文榜'
:
'https://tophub.today/n/WnBe01o371'
,
'澎湃 ‧ 首页要闻'
:
'https://tophub.today/n/5PdMxAbvmg'
,
'百度实时热点'
:
'https://tophub.today/n/Jb0vmloB1G'
,
'吾爱破解 ‧ 今日热帖'
:
'https://tophub.today/n/NKGoRAzel6'
,
'吾爱破解 ‧ 原创发布区'
:
'https://tophub.today/n/qndgO7LdLl'
,
'知乎热榜'
:
'https://tophub.today/n/mproPpoq6O'
,
'虎嗅热文'
:
'https://tophub.today/n/5VaobgvAj1'
,
'哔哩哔哩全站排行'
:
'https://tophub.today/n/74KvxwokxM'
,
'抖音热搜'
:
'https://tophub.today/n/K7GdaMgdQy'
,
'抖音 ‧ 正能量榜'
:
'https://tophub.today/n/1yjvQqDvbg'
,
'豆瓣电影 ‧ 最受欢迎的影评'
:
'https://tophub.today/n/2me38jrowj'
}
self
.add_url_box()
self
.post_url()
def
delButton(
self
, tree):
x
=
tree.get_children()
for
item
in
x:
tree.delete(item)
def
get_text(
self
, hot_url):
response
=
get(url
=
hot_url, headers
=
HEADERS)
html
=
etree.HTML(response.content.decode(
'utf-8'
))
self
.delButton(tree)
ind
=
0
[
/
align]
[align
=
left]
def
add_url_box(
self
):
self
.xaunze_
=
ttk.Combobox(root, font
=
(
'宋体'
,
16
,
"bold"
), width
=
18
, state
=
"readonly"
)
hot_title_list
=
[]
for
hot_title
in
self
.all_url:
hot_title_list.append(hot_title)
self
.xaunze_[
'value'
]
=
tuple
(hot_title_list)
self
.xaunze_.current(
0
)
self
.xaunze_.place(x
=
14
, y
=
14
)
def
post_url(
self
):
hot_title
=
self
.xaunze_.get()
title_url
=
self
.all_url[hot_title]
Thread(target
=
self
.get_text, args
=
(title_url,)).start()
def
gogo(
self
):
if
str
(
len
(tree.selection())) !
=
"0"
:
for
items
in
tree.selection():
item_text
=
tree.item(items,
"values"
)[
2
]
print
(
"已选择:"
+
item_text)
if
item_text !
=
"":
Thread(target
=
gogo_start, args
=
(item_text,)).start()
else
:
messagebox.showinfo(
'提示'
,
"没有选择新闻词条!"
)
if
__name__
=
=
'__main__'
:
root
=
tkinter.Tk()
root.title(
"Taday_Hot 重置版 - 内容来源:【今日热榜】 - By:jingmo"
)
root.geometry(
"700x400+700+360"
)
root.resizable(
False
,
False
)
Thread(target
=
app_info, args
=
()).start()
tree
=
ttk.Treeview(root, height
=
16
, show
=
"headings"
)
style_head
=
ttk.Style()
style_head.configure(
"Treeview"
, font
=
"微软雅黑"
)
tree[
"columns"
]
=
(
"热度"
,
"事件"
)
tree.column(
"热度"
, width
=
100
, anchor
=
'center'
)
tree.column(
"事件"
, width
=
600
, anchor
=
'center'
)
tree.heading(
"热度"
, text
=
"热度"
)
tree.heading(
"事件"
, text
=
"-- 事件 --"
)
VScroll1
=
ttk.Scrollbar(tree, orient
=
'vertical'
, command
=
tree.yview)
VScroll1.place(relx
=
0.97
, rely
=
0.005
, relwidth
=
0.024
, relheight
=
0.99
)
tree.configure(yscrollcommand
=
VScroll1.
set
)
tree.place(x
=
0
, y
=
50
)
ui
=
SpinderMain()
chaxunde
=
tkinter.Button(root, text
=
"查询"
, font
=
(
'宋体'
,
12
,
"bold"
), width
=
9
, command
=
ui.post_url)
chaxunde.config(fg
=
"orange"
, bg
=
"white"
)
chaxunde.place(x
=
260
, y
=
12
)
app_info_
=
tkinter.Button(root, text
=
"GO—>"
, font
=
(
'宋体'
,
12
,
"bold"
), width
=
12
, command
=
ui.gogo)
app_info_.config(fg
=
"green"
, bg
=
"white"
)
app_info_.place(x
=
550
, y
=
12
)
root.mainloop()