当前位置:网站首页>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
边栏推荐
- [golang] golang develops wechat official account web page authorization function
- JS存取cookie示例
- Shell enterprise interview exercise
- 二零二零年终总结
- Day111.尚医通:集成NUXT框架、前台页面首页数据、医院详情页
- 孙子出题难,儿子监考严。老子不会做,还我上学钱
- Dasctf2022.07 enabling game password WP
- [resolved] the new version of pychart (2022) connects to the server to upload files and reports an error of "command Rsync is not found in path", and the files cannot be synchronized
- 一文速览EMNLP 2020中的Transformer量化论文
- Harbor正确密码登录不上去
猜你喜欢

C event usage case subscription event+=

RPC remote procedure call

Qt Creator代码风格插件Beautifier

企业架构驱动的数字化转型!

一文速览EMNLP 2020中的Transformer量化论文

数据提取1

PHP realizes data interaction with MySQL

An ordinary autumn recruitment experience

Solve the problem of slow batch insertion of MySQL JDBC data

File name wildcard rules for kettle
随机推荐
擎创科技加入龙蜥社区,共建智能运维平台新生态
反弹shell是什么?反弹shell有什么用?
What other methods are available for MySQL index analysis besides explain
Harbor can't log in with the correct password
【Day42 文献精读】A Bayesian Model of Perceived Head-Centered Velocity during Smooth Pursuit Eye Movement
SQL labs SQL injection platform - level 1 less-1 get - error based - Single Quotes - string (get single quote character injection based on errors)
C语言:随机生成数+希尔排序
Lua stateful iterator
I can't figure out why MySQL uses b+ trees for indexing?
如何在 60 秒内去分析和定位问题?
Modification case of Ruixin micro rk3399-i2c4 mounting EEPROM
Is redis really slowing down?
二零二零年终总结
3D laser slam: Interpretation of logo-loam paper --- Abstract
JS access cookie example
Demo submit a program and obtain ALV data of the program
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
浅谈数据安全
Dormitory access control system made by imitating the boss (III)
C language: random number + Hill sort