当前位置:网站首页>Design and development of GUI programming for fixed-point one click query
Design and development of GUI programming for fixed-point one click query
2022-07-27 08:04:00 【Shenzhi Kalan Temple】
background
A few days ago, a friend asked me how I can query data at a fixed point and format the output , Because most of the advertisements and links found on Baidu , Useful information needs to be filtered manually , More trouble .
In essence, his demand is more about reptiles , That is to query data from Baidu , And present in a structured form . Live here , I thought of before in git Baidu spider seen on (BaiduSpider) Open source project , I think I can use it as the core to develop , In view of friends IT The technical ability is not so good , Then recombine python Of GUI Programming Tkinter Come and wrap him up , Just give him one exe Executable files on the computer , Open and run to facilitate query and data pasting ,Demo The sample figure is as follows

Development
Baidu spider's open source project is :https://github.com/BaiduSpider/BaiduSpider ( Thank God )
We can use the project immediately , Do some small specific development
The main program
def btn_click():
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36"
}
search_wds = ipText.get()
response = requests.get('https://www.baidu.com/s?wd=%s&lm=1&pn=%d0' % (search_wds,pn), headers=headers)
r = response.text
html = etree.HTML(r, etree.HTMLParser())
r1 = html.xpath('//h3')
r2 = html.xpath('//*[@class="c-abstract"]')
r3 = html.xpath('//*[@class="t"]/a/@href')
if len(r1) == 0:
# Adjust font highlighting
ft = tf.Font(family=' Microsoft YaHei ',size=10)
text.tag_config('tag',foreground = 'red',background='pink',font = ft)
text.insert(INSERT," This machine IP Has been banned , Please test later or change the network !\n",'tag')
else:
try:
for i in range(50):
r11 = r1[i].xpath('string(.)')
r22 = r2[i].xpath('string(.)')
r33 = r3[i]
# text.insert(INSERT,('%s\n' % r11))
text.insert(INSERT,('------------------------------------------------------------------------\n'))
text.insert(INSERT,('<%d>%s\n' % (i+1,r22)))
text.insert(INSERT,('<%d>%s\n' % (i+1,r33)))
except:
text.insert(INSERT,("\n############################ Page break ############################\n"))Architecture program
# enter call
def btn_click_enter(self):
global pn
pn = 0
btn_click()
# Clear the message
def cleartext():
text.delete('0.0', END)
def next_pn():
global pn
pn += 1
btn_click()Full code
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File : BaiduSpider.py
@Contact : [email protected]
@License : (C)Copyright 1997-2020, XXXXXXXXXXXXX CO.,LTD.
@Modify Time @Author @Version @Desciption
------------ ------- -------- -----------
2021/11/24 0:0 liqb 1.0 kill some bugs
"""
from tkinter import *
import tkinter.font as tf
import json
import requests
from lxml import etree
global pn
pn = 0
def btn_click():
headers = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36"
}
search_wds = ipText.get()
response = requests.get('https://www.baidu.com/s?wd=%s&lm=1&pn=%d0' % (search_wds,pn), headers=headers)
r = response.text
html = etree.HTML(r, etree.HTMLParser())
r1 = html.xpath('//h3')
r2 = html.xpath('//*[@class="c-abstract"]')
r3 = html.xpath('//*[@class="t"]/a/@href')
if len(r1) == 0:
# Adjust font highlighting
ft = tf.Font(family=' Microsoft YaHei ',size=10)
text.tag_config('tag',foreground = 'red',background='pink',font = ft)
text.insert(INSERT," This machine IP Has been banned , Please test later or change the network !\n",'tag')
else:
try:
for i in range(50):
r11 = r1[i].xpath('string(.)')
r22 = r2[i].xpath('string(.)')
r33 = r3[i]
# text.insert(INSERT,('%s\n' % r11))
text.insert(INSERT,('------------------------------------------------------------------------\n'))
text.insert(INSERT,('<%d>%s\n' % (i+1,r22)))
text.insert(INSERT,('<%d>%s\n' % (i+1,r33)))
except:
text.insert(INSERT,("\n############################ Page break ############################\n"))
# enter call
def btn_click_enter(self):
global pn
pn = 0
btn_click()
# Clear the message
def cleartext():
text.delete('0.0', END)
def next_pn():
global pn
pn += 1
btn_click()
# Create the background color of the window object
root = Tk()
root.title(' Baidu spider one click query service system - Zhongyu Special Edition ')
root.geometry('960x700')
# Frame For layout functions
main_frame = Frame(root)
text_frame = Frame(main_frame)
station_frame = Frame(main_frame)
botton_frame = Frame(station_frame)
# Create a list
l1 = Label(station_frame,text=' Enter the content you want to retrieve , With | Split filter criteria ')
#l2 = Label(station_frame,text='')
ipText=Entry(station_frame)
# Font display
# ft = tkFont.Font(family='Fixdsys', size=10, weight=tkFont.BOLD)
# pack It's loaded into the window
l1.pack(side='left')
ipText.pack(side='left')
ipText['width']=24
#l2.pack(side='left')
'''
The meaning of the two functions is that they can be enter function , You can click run again , Convenient operation , Expand the use of
bind binding enter key
Notice that it's return instead of enter
'''
b = Button(station_frame,text=' Inquire about ',command=btn_click)
b['width']=4
b['height']=1
b.pack(side='left')
ipText.bind("<Return>", btn_click_enter)
# Message input interface
text = Text(text_frame,width = 130, height= 39)
text.pack()
main_frame.pack()
c = Button(text=' Empty ',command=cleartext)
c['width']=4
c['height']=1
c.pack(side='left')
# The second function
d = Button(text=' The next page ',command=next_pn)
d['width']=8
d['height']=1
d.pack(side='top')
# The position of the input box
station_frame.pack(side='top',pady='10')
text_frame.pack()
# Enter the message loop
root.mainloop()Final use pyinstaller Pack it up windows The executable file of
pyinstaller -F -w BaiduSpider.py
Be careful 32 Bit and 64 The difference between bits
边栏推荐
猜你喜欢

C commissioned use cases

C#winform 窗体事件和委托结合用法
![[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel](/img/fc/1ee8b77d675e34da2eb8574592c489.png)
[ten thousand words long article] thoroughly understand load balancing, and have a technical interview with Alibaba Daniel

【目标检测】YOLOv6理论解读+实践测试VisDrone数据集

Things come to conform, the future is not welcome, at that time is not miscellaneous, neither love
Why do major domestic manufacturers regard cloud computing as a pastry? Do you really understand this trillion market

Day111. Shangyitong: integrate nuxt framework, front page data, hospital details page
![[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP](/img/0c/da2ffc00834793c7abc0f7ebe6321b.png)
[applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP

On data security

数据提取1
随机推荐
Internet of things industrial UART serial port to WiFi to wired network port to Ethernet Gateway WiFi module selection
[resolved] SSO forwarding succeeded, and there was an unexpected error (type=internal server error, status=500) caused by parameters in the forwarding URL
Opengauss stopped from the library and found that the main library could not write data
杂谈:把肉都烂在锅里就是保障学生权益了?
2020国际机器翻译大赛:火山翻译力夺五项冠军
浅谈数据安全
Dormitory access control system made by imitating the boss (III)
Stored procedures and functions
MCU multi-level menu
想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
数据提取1
Shell scripts related
C language: random number + Hill sort
C commissioned use cases
[flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
How to update PIP3? And running PIP as the 'root' user can result in broken permissions and conflicting behavior
linux能不能安装sqlserver
【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
大家节日快乐哈
企业架构驱动的数字化转型!