以下是使用Python的Tkinter库编写的简单界面,可以实现上述功能:

import requests
from lxml import etree
import tkinter as tk
import webbrowser

# 获取新闻列表
url = 'https://www.court.gov.cn/zixun.html'
response = requests.get(url)
html = response.content.decode('utf-8')
tree = etree.HTML(html)
data_list = tree.xpath('/html/body/div[6]/div[2]/div[1]/div[1]/div[2]/ul/li')

# 创建窗口
window = tk.Tk()
window.title('法院新闻')
window.geometry('400x300')

# 创建标题列表框架
title_frame = tk.Frame(window)
title_frame.pack(side='top', fill='both', expand=True)

# 创建滚动条
scrollbar = tk.Scrollbar(title_frame)
scrollbar.pack(side='right', fill='y')

# 创建标题列表
title_list = tk.Listbox(title_frame, yscrollcommand=scrollbar.set)
for data in data_list:
    title = data.xpath('./a/text()')[0]
    link = data.xpath('./a/@href')[0]
    title_list.insert('end', title)
    title_list.bind('<Double-Button-1>', lambda event: webbrowser.open(link))

title_list.pack(side='left', fill='both', expand=True)
scrollbar.config(command=title_list.yview)

window.mainloop()

运行以上代码将会得到一个简单的窗口界面,其中包含了法院新闻的标题列表,点击标题将会在浏览器中打开对应的链接

使用python写一个界面把这段代码import requestsfrom lxml import etreeurl = httpswwwcourtgovcnzixunhtmlresponse = requestsgeturlhtml = responsecontentdecodeutf-8tree = etreeHTMLhtmldata_list = treexpathhtmlbodydiv6d

原文地址: https://www.cveoy.top/t/topic/gDKp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录