Python simulated Mouse clicking implementation method (automatically search for python in the browser through instance simulation), python

Source: Internet
Author: User
Tags lenovo


I. preparations:

Install pywin32. Later development requires the support of pywin32. Otherwise, operations related to windows cannot be completed.

Pywin32 installation and precautions:

1. Overall Development Environment:

Based on the Windows 7 operating system;

Install python in advance (due to space issues, we will not detail the installation of the python environment here. You can bring your own stairs );

You can test whether the python environment is installed in cmd:


You can see that Python has been installed on my computer and the version is V 3.6.2.

Note: you must know the Python version number on your computer. The later version of pywin32 must correspond to the python version.

2. Installation Method and detailed steps:

First download the pywin32 installation package

1. Access pywin32: https://sourceforge.net/projects/pywin32/files/pywin32/

②. Download The pywin32 installation package corresponding to the python version installed on your computer. For example, the installation package of the 64bit python3.6.2 is pywin32-221.win-amd64-py3.6.exe.


Select the pywin32-221.win-amd64-py3.6.exe file to download it to the local device. The size is 9.5 MB, which is not very large. the download is fast.


3.install the downloaded pywin32-221.win-amd64-py3.6.exe installation package and double-click it to run it. Then, click Next to complete the installation.

Note that the installation directory cannot be changed by yourself. The system will automatically enter the installation directory based on the python installation path on your computer,

Python on my computer is installed in C: \ Users \ lenovo \ AppData \ Local \ Programs \ Python \ Python36;

Therefore, the system will automatically install pywin32 in C according to the Python installation directory I installed: \ Users \ lenovo \ AppData \ Local \ Programs \ Python \ Python36 \ Lib \ site-packages \ directory.

If the system does not automatically enter the pywin32 installation directory during the installation process, it indicates that your python installation is faulty. Check whether your python installation has any problems. (Note: configure the environment variables after installing Python)


If you still win, congratulations.

④ To ensure that pywin32 is successfully installed, check the installation result and enter import win32api In the python command line.


You can also test whether pywin32 is successful in python shell.


If it succeeds, there will be PythonWin under the python3.6 directory in the Start Menu.


If no error is reported in the above test and PythonWin exists in the Start menu, the installation of Pywin32 is successful.

If an error is reported, the environment variable PYTHONPATH is not configured properly.

⑤ Configure the PYTHONPATH environment variable. In this case, you need to add the site-packages path in the lib directory under the python installation directory to the PYTHONPATH environment variable.

Note: PYTHONPATH is a user variable. If you do not have this option, you can create a new one.





You can view the path in CMD.


⑥ Everyone must ensure that the pywin32 version is consistent with the python version, and the support for 32-bit and 64-bit must be consistent with that for python. The 64-bit system will install the 64-bit pywin32 version, install pywin32 with 32 bits.

If any problem occurs, repeat Step 5 to verify the installation configuration and then check the test.

2. Start development:

1. Open pythonwin from the Start Menu



2. Create a. py file in pythonWin:


When creating a file, select Python Script in the pop-up window and click OK.


3. Start encoding: directly upload the code.

## _*_ coding:UTF-8 _*_import win32apiimport win32conimport win32guifrom ctypes import *import time

Import win32api, win32con, and win32gui In the Python program, and introduce the ctypes module to load the dynamic link library (C function will be used later ).

If you want to learn more about how to use the C function to call ctypes in Python, you can call the C function printf in Python.


The VK_CODE value corresponding to the symbol on the keyboard. For more information, see.

Test. py



When you run test. py, the system automatically enters python in the search box and clicks the search button to start searching.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.