99 lines
3.2 KiB
Plaintext
99 lines
3.2 KiB
Plaintext
|
|
||
|
from email import header
|
||
|
from glob import glob
|
||
|
from sqlite3 import DataError
|
||
|
from tkinter import *
|
||
|
from wsgiref import headers
|
||
|
import requests
|
||
|
import jsonpath
|
||
|
import os
|
||
|
|
||
|
headersa = {}
|
||
|
url = {}
|
||
|
def get_headers():
|
||
|
global headersa
|
||
|
headersa[entry1.get()] = entry4.get()
|
||
|
entry1.delete(0,END)
|
||
|
entry4.delete(0,END)
|
||
|
print(headersa)
|
||
|
def get_url():
|
||
|
global url
|
||
|
url = entry.get()
|
||
|
print(url)
|
||
|
|
||
|
datea = {}
|
||
|
def get_date():
|
||
|
global datea
|
||
|
if entry2.get():
|
||
|
datea[entry2.get()] = entry3.get()
|
||
|
entry2.delete(0,END)
|
||
|
entry3.delete(0,END)
|
||
|
print(datea)
|
||
|
|
||
|
def query_date():
|
||
|
global url
|
||
|
global headersa
|
||
|
global datea
|
||
|
headers = {
|
||
|
"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
|
||
|
# 判断请求是异步还是同步
|
||
|
"x-requested-with":"XMLHttpRequest",
|
||
|
}
|
||
|
|
||
|
res = requests.post(url=url,data=datea,headers=headersa)
|
||
|
|
||
|
json_text = res.json()
|
||
|
|
||
|
print(json_text)
|
||
|
with open(file = 'date.txt',mode='w') as f:
|
||
|
f.write(str(json_text))
|
||
|
text.delete(0,END)
|
||
|
text.insert(END,json_text)
|
||
|
root = Tk()
|
||
|
# 设置窗口标题
|
||
|
root.title('数据爬取器')
|
||
|
# 设置窗口大小以及出现的位置
|
||
|
root.geometry('700x650+400+50')
|
||
|
# 标签组件
|
||
|
label = Label(root,text="请输入要爬取的网页:",font=('楷体',20))
|
||
|
label.place(relx=0,y=0,relheight=0.1,width=300)
|
||
|
label1 = Label(root,text="headers:",font=('楷体',20))
|
||
|
label1.place(relx=0,y=370,relheight=0.1,width=200)
|
||
|
label2 = Label(root,text="请求数据",font=('楷体',20))
|
||
|
label2.place(relx=0,y=420,relheight=0.1,width=200)
|
||
|
label5 = Label(root,text="节点:",font=('楷体',20))
|
||
|
label5.place(relx=0.28,y=370,relheight=0.1,width=100)
|
||
|
label6 = Label(root,text="属性:",font=('楷体',20))
|
||
|
label6.place(relx=0.56,y=370,relheight=0.1,width=100)
|
||
|
label3 = Label(root,text="节点:",font=('楷体',20))
|
||
|
label3.place(relx=0.28,y=420,relheight=0.1,width=100)
|
||
|
label4 = Label(root,text="属性:",font=('楷体',20))
|
||
|
label4.place(relx=0.56,y=420,relheight=0.1,width=100)
|
||
|
|
||
|
# 输入框组件
|
||
|
entry = Entry(root,font=('宋体',15))
|
||
|
entry.place(relx=0.4,y=15,relheight=0.05,width=300)
|
||
|
entry1 = Entry(root,font=('宋体',15))
|
||
|
entry1.place(relx=0.4,y=390,relheight=0.05,width=100)
|
||
|
entry4 = Entry(root,font=('宋体',15))
|
||
|
entry4.place(relx=0.68,y=390,relheight=0.05,width=100)
|
||
|
entry2 = Entry(root,font=('宋体',15))
|
||
|
entry2.place(relx=0.4,y=430,relheight=0.05,width=100)
|
||
|
entry3 = Entry(root,font=('宋体',15))
|
||
|
entry3.place(relx=0.68,y=430,relheight=0.05,width=100)
|
||
|
# 列表框
|
||
|
text = Listbox(root,font=('楷体',16),width=50,height=15)
|
||
|
text.place(relx=0,y=60,relheight=0.5,width=700)
|
||
|
# 按钮
|
||
|
button1 = Button(root,text='确认',font=('楷体',15),command=get_url)
|
||
|
button1.place(relx=0.84,y=15,relheight=0.05,width=100)
|
||
|
button2 = Button(root,text='确认',font=('楷体',15),command=get_headers)
|
||
|
button2.place(relx=0.84,y=390,relheight=0.05,width=100)
|
||
|
button3 = Button(root,text='确认',font=('楷体',15),command=get_date)
|
||
|
button3.place(relx=0.84,y=430,relheight=0.05,width=100)
|
||
|
button4 = Button(root,text='获取数据',font=('楷体',15),command=query_date)
|
||
|
button4.place(relx=0.5,y=500,relheight=0.05,width=100)
|
||
|
# 显示界面
|
||
|
root.mainloop()
|
||
|
# 如何将.py代码打包成.exe文件
|