Python基础之tkinter界面爬虫采集(补充完善添加翻页功能)

时间:2025-04-03 13:12:59
  • """
  • # @当前时间 :2024/8/19 13:08
  • # @Author : TS
  • # @Email : TS@
  • # @File :
  • # @Software: PyCharm
  • """
  • import math
  • from import ThreadPoolExecutor
  • from tkinter import filedialog, messagebox
  • from slider_tk import Slider_tk
  • from slider_kz import Slide_kz
  • from slider_kz import Fart_pi
  • from dj_zk import Yj_youyou
  • class Slider_subassembly(Slider_tk):
  • def __init__(self, root=None):
  • super().__init__(root=root)
  • = root
  • = Slide_kz()
  • = Fart_pi()
  • = Yj_youyou()
  • self.submit_button_dj.config(command=self.dj_searcj)
  • self.submit_button.config(command=self.on_submit)
  • self.submit_button2.config(command=self.on_submt)
  • self.submit_button_pe.config(command=)
  • ("<Button-1>", self.on_tree_click)
  • ()
  • #
  • def show(self):
  • self.(x=10, y=20, )
  • self.Labe_lFram6.place(x=2, y=190, width=400, height=5)
  • self.Labe_lFram5.place(x=2, y=110, width=400, height=5)
  • self.Labe_lFram4.place(x=2, y=150, width=400, height=5)
  • self.Labe_lFram3.place(x=2, y=1, width=997, height=50)
  • self.Labe_lFrame.place(x=2, y=50, width=400, height=448)
  • self.Labe_lFram2.place(x=400, y=50, width=600, height=440)
  • (x=4, y=80, )
  • (x=100, y=80)
  • self.submit_button.place(x=340, y=78,)
  • self.(x=4, y=125, )
  • self.(x=100, y=125)
  • self.submit_button2.place(x=340, y=120, )
  • (x=404, y=68, height=418, width=593, )
  • # 绑定鼠标点击事件
  • self.label_dj.place(x=4, y=165)
  • self.label_pa.place(x=4, y=210)
  • self.entry2_dj.place(x=80, y=165)
  • self.entry2_pa.place(x=80, y=210)
  • self.submit_button_dj.place(x=270, y=160)
  • self.submit_button_pe.place(x=340, y=210)
  • def search_(self):
  • ['columns'] = ('serial', 'id', 'singer', 'name', 'url')
  • for col in ['columns']:
  • (col, text=col)
  • ('serial', width=2, )
  • ('id', width=2, )
  • ('singer', width=2)
  • ('name', width=2, )
  • ('url', width=2, )
  • n=0
  • params = ()
  • pase = (params)
  • dict_ =(pase)
  • for di_ct in dict_:
  • id = di_ct['id']
  • song_name = di_ct['song_name']
  • singer = di_ct['singer']
  • url_ = di_ct['url']
  • ("", "end", values=(n, id, singer,song_name, url_))
  • n+=1
  • def Page(self):
  • Page = self.entry2_pa.get()
  • (*.get_children())
  • self.dj_searcj(Page)
  • def dj_searcj(self,page=None):
  • ['columns'] = ('serial', 'id','name','time', '页数', 'url')
  • for col in ['columns']:
  • (col, text=col)
  • ('serial', width=2, )
  • ('id', width=2, )
  • ('页数', width=2)
  • ('name', width=2, )
  • ('time', width=2, )
  • ('url', width=2, )
  • n = 0
  • params = self.entry2_dj.get()
  • pase = (params,page)
  • dict_ = .url_dq(pase)
  • for i in dict_:
  • name = i['name']
  • Pages = i['Recording'] #页数
  • li_url = i['li_url']
  • id_st = i['id_st']
  • time_s=i['time_s']
  • divisor = 20
  • result = (int(Pages) / divisor)
  • # print(n, id_st, name,time_s,result,li_url)
  • ("", "end", values=(n, id_st, name,time_s,result,li_url))
  • n += 1
  • def on_tree_cli(self):
  • ['columns'] = ('serial', 'id', 'singer', 'name', 'url')
  • for col in ['columns']:
  • (col, text=col)
  • ('serial', width=2, )
  • ('id', width=2, )
  • ('singer', width=2)
  • ('name', width=2, )
  • ('url', width=2, )
  • n=0
  • params = self.()
  • pase=(params)
  • dict_=(pase)
  • for di_ct in dict_:
  • id = di_ct['songid']
  • song_name = di_ct['author']
  • singer = di_ct['title']
  • url_ = di_ct['Location']
  • ("", "end", values=(n, id, singer, song_name, url_))
  • n += 1
  • def on_tree_click(self, event):
  • if == :
  • # 获取双击的item
  • item = .identify_row()
  • if item:
  • # 获取item的values
  • values = (item, "values")
  • # # 假设values是一个元组,包含了歌曲的id, song_name, singer, url等信息
  • url = values[-1]
  • song_name = values[2]
  • download_message = "是否下载"
  • if ("Download",download_message):
  • .save_mp3(url,song_name)
  • # ("下载完毕!",download_messa)
  • ("下载完毕", song_name)
  • def on_submit(self):
  • (*.get_children()) # 清空树形控件数据
  • self.search_() # 传入回调函数
  • def on_submt(self):
  • (*.get_children()) # 清空树形控件数据
  • self.on_tree_cli() # 传入回调函数
  • def dj_submt(self):
  • (*.get_children()) # 清空树形控件数据
  • self.dj_searcj()