赞
踩
在main.py文件中进行以下操作。
一、程序入口,明白接下来进行的操作
1、加载UI界面。
2、爬取网页内容。
#程序入口
if __name__ == "__main__":
t1=threading.Thread(target=thread_one) #创建t1线程用于加载UI界面
t1.start() #启动t1线程
t3=threading.Thread(target=thread_three) #创建t3线程用于检测UI界面中的输入框是否有输入
t3.start() #启动t3线程
t4=threading.Thread(target=thread_four) #创建t4线程用于循环获取UI界面输入框中的内容
创建UI.py文件
UI界面代码如下:
from tkinter import * class ui(object): test = False txt='' def loading(self): root = Tk() root.title("微博爬取器") root.geometry("600x400") #创建文本框 return root def Text(self,root): text=Entry(root,bd=0) text.place(x=200, y=180, width=175, height=40) return text #第一种方法 # @staticmethod # def fuc(text): # # 获取用户输入 # txt = text.get() # print(txt) # 第二种方法 def fuc(self,text): # 获取用户输入 # ui.txt = text.get() print("执行了") ui.test=True # 创建搜索按钮 def ButtoN(self,root,text): button=Button(root,command=lambda: ui.fuc(self,text)) button.place(x=390, y=180, width=40, height=40) def show(self,root): root.mainloop()
# from selenium import webdriver # from selenium.webdriver.chrome.options import Options # from selenium.webdriver.common.keys import Keys import time,threading from UI import ui from lxml import etree import requests #加载UI用户界面 list_var=[] #list_var用于接收从UI界面中输入框里获取的内容 test=False #test用于作为检测是否可以执行thread_two()方法的条件。如果test为True则会被t3线程检测到,从而 #执行thread_two()方法。为False则会不做处理。 list_var1=[] #list_var1 def thread_one(): gc = ui() #创建UI文件里的ui类的实例对象gc root = ui.loading(gc) #调用ui类的loading()方法并传入实例对象,返回得到主界面对象root global list_var1 #在thread_one()方法中对其声明使用全局成员列表list_var1 text = ui.Text(gc, root) #调用ui类的Text()方法传入实例对象gc与主界面对象root,并返回得到文本框控件对象text list_var1.append(text) #将文本框控件对象text添加到列表list_var1中,方便之后使用这个对象 ui.ButtoN(gc, root, text) #使用ui类的ButtoN的方法(),并传入实例对象gc、主界面对象root、文本框控件对象text t4.start() #启动t4线程 ui.show(gc, root) #调用ui
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。