|  | 
 
 
 楼主|
发表于 2021-7-21 16:54:16
|
显示全部楼层 
| from tkinter import *
 import requests,os,time
 from bs4 import BeautifulSoup
 q=None
 
 def submit():
 print(u.get())
 zc=list(u.get())
 zc=''.join(zc)
 ##    zx=['\'','\'']
 ##    zv=zx[0]+zc+zx[1]
 url=zc
 res = requests.get(url)
 soup = BeautifulSoup(res.text, 'lxml')
 s = open(r'C:\Users\Administrator.TK-20180903IUNE\Desktop/该网页所有网页链接.txt','w')
 for a in soup.find_all('a'):
 
 print(a['href'])
 s.write(a['href']+'\n')
 #print(url,type(url))
 print('*'*90)
 s.close()
 
 
 
 root = Tk()
 root.title("测试")
 frame = Frame(root)
 frame.pack(padx=8, pady=8, ipadx=4)
 lab1 = Label(frame, text="获取:")
 lab1.grid(row=0, column=0, padx=5, pady=5, sticky=W)
 
 
 
 #绑定对象到Entry
 
 u = StringVar()
 
 ent1 = Entry(frame, textvariable=u)
 ent1.grid(row=0, column=1, sticky='ew', columnspan=2)
 
 
 button = Button(frame, text="确定", command=submit, default='active')
 button.grid(row=2, column=1)
 
 button2 = Button(frame, text="退出", command=quit)
 button2.grid(row=2, column=2, padx=5, pady=5)
 
 
 #以下代码居中显示窗口
 
 root.update_idletasks()
 x = (root.winfo_screenwidth() - root.winfo_reqwidth()) / 2
 y = (root.winfo_screenheight() - root.winfo_reqheight()) / 2
 root.geometry("+%d+%d" % (x, y))
 mainloop()
 time.sleep (1)
 
 
 
 
 | 
 |