当前位置:网站首页>great! Auto like, I use pyautogui!
great! Auto like, I use pyautogui!
2022-06-25 04:45:00 【Python Technology】

writing | Leisure and joy
source :Python technology 「ID: pythonall」

In the last article 《Python Automatic operation GUI Artifact ——PyAutoGUI》 in , I explained to you pyautogui Some basic knowledge and operation of , The feedback is very good , Gave me a lot of praise , First of all, I want to tell you about three grams of oil !
While getting positive feedback from everyone , I was greatly encouraged , I feel that if I just introduce the basic operation , It's a bit addictive , So I worked overtime tonight , Although I don't want to open the computer , But I still have to bear the fatigue to give you a small example .
So , I went to the bathroom and washed my face with cold water , I was much more awake , Let's get to the point .
As a GUI Artifact of operation , We have seen that its operation is very simple , It's very easy to understand , Basically, you can see the function and know its function .
Let me show you a little chestnut , After reading this chestnut, you will understand the origin of its artifact .
Okay , Don't beat around the bush , Today's little chestnut is a lot of praise for Zhihu's articles .
Ideas
Let's take a look at Zhihu's personal homepage :

here , I will take the following tab Tab switch to the article here , What is displayed is the author's article list .
Let's think about it first , If I want to praise this author's article , What do I need to do ?
First , I need to find a like icon ; then , I click the like icon , Complete a like ; When I like the articles in my field of vision , I drag the page down , Continue with the above steps .
See here , Do you think it's a little bit strange to say so ?
But we have to write programs like this , Make every step clear , Then write the logic according to the steps , Or when you start writing logic , You may miss some details , Cause the program to fail to achieve the desired effect , or bug.
Realization
With the above steps , We can start developing code .
First , I want the program to recognize the like button . In the last article, I introduced a little chestnut , Is to find the browser icon on the desktop , We need to save the icon screenshot of the browser as a picture , Then pass it to the program , Let the program use this picture to look in the screen .
Same thing here , I first cut off the like button of Zhihu :

Follow the steps above , I first need to identify the like button on the current desktop , Just one line of code :
allLocation = pyautogui.locateAllOnScreen('agree.png')In this way, you can find all the like buttons on the desktop .
After finding the like button , The next step is to like :
def like():
time.sleep(1)
if pyautogui.locateOnScreen('agree.png'):
left, top, width, height = pyautogui.locateOnScreen('agree.png')
center = pyautogui.center((left, top, width, height))
pyautogui.click(center)
print(' I like it !')here , I had a rest first 1 Second , Prevent the program from running too fast , Crash the page or trigger the security policy of the platform .
Then I found the like button , Calculate the center point of the button , Then click .
such , We successfully completed a like operation .
then , Let me write another judgment , If the like buttons on the current desktop have been clicked , Just scroll the screen , Continue to like on the next screen :
while True:
allLocation = pyautogui.locateAllOnScreen('agree.png')
if len(list(allLocation)) > 0:
like() # Call the praise function
else:
try:
pyautogui.scroll(-500)
print(' I'm out !')
except:
print(' It's over ')The whole code runs like this :

Be careful , While the program is running , Be sure to switch the browser that opens the Zhihu page to the top of the desktop , To ensure that you are currently working on this page .
There is no termination condition here , So the program will run forever , Until you manually terminate .
summary
The whole chestnut is like this , Simple but not simple , Although only a few lines of code , But I finished an automatic operation for me . Perhaps the example given here is not appropriate , Because there are pages , If it's a waterfall page , That really can continue to praise , Maybe you can try giving csdn Like your article .
PS: Reply within company number 「Python」 You can enter Python Novice learning communication group , Together 100 Day plan !
Old rules , Brothers, remember , Right lower corner “ Looking at ” click , If you think the content of the article is good , Remember to share the circle of friends and let more people know !

【 Code Access method 】
Identify the QR code at the end of the text , reply : Leisure and joy

边栏推荐
- Package for gbase 8s
- CTF_ Web: Changan cup-2021 old but a little new & asuka
- Deep learning - several types of learning
- 台式电脑连不上wifi怎么办
- Méthode de récupération des données d'ouverture du disque dur à l'état solide
- Solution of gbase 8s livelock and deadlock
- OOP栈类模板(模板+DS)
- Introduction to the isolation level of gbase 8s
- dotnet-exec 0.4.0 released
- js中的concat()
猜你喜欢

为什么SQL语句命中索引比不命中索引要快?

【FLink】access closed classloader classloader.check-leaked-classloader

Simple text analysis of malicious samples - Introduction

CTF_ Web: deserialization of learning notes (II) CTF classic test questions from shallow to deep

我的IC之旅——资深芯片设计验证工程师成长——“胡”说IC工程师完美进阶

Part I Verilog quick start

CTF_ Web: how to recognize and evaluate a regular expression

Record the problem of C # print size once
![[untitled]](/img/68/5e711f7c473dcea54a56f7b7e48604.png)
[untitled]

绝了!自动点赞,我用 PyAutoGUI!
随机推荐
电脑的dwg文件怎么打开
leetcode1221. 分割平衡字符串
OOP栈类模板(模板+DS)
【无标题】
Codeforces Round #802 (Div. 2) C D
Le chemin de l'apprentissage immutable - - Adieu à la copie traditionnelle
Gbase 8s parallel operation problem scenario description
STM32的DMA双缓冲模式详解
"Daily practice, happy water" 1108 IP address invalidation
Immutable学习之路----告别传统拷贝
大话云原生数据库中的存算分离
Gbase 8s stored procedure syntax structure
js的sort()函数
CTF_ Web: Advanced questions of attack and defense world expert zone WP (15-18)
GBASE 8s中DELIMIDENT环境变量的使用
Machine learning deep learning -- Vectorization
How to apply for software
MySQL concept and operation (III)
WPF 使用 MAUI 的自绘制逻辑
GBASE 8s的包