python实现rpa机器人
python安装
pip安装
需要先把get-pip.py保存到本地
C:\Users\WWKJ>py get-pip.py
Collecting pip
Downloading pip-22.0.4-py3-none-any.whl (2.1 MB)
---------------------------------------- 2.1/2.1 MB 14.2 kB/s eta 0:00:00
Collecting wheel
Downloading wheel-0.37.1-py2.py3-none-any.whl (35 kB)
Installing collected packages: wheel, pip
Attempting uninstall: pip
Found existing installation: pip 22.0.4
Uninstalling pip-22.0.4:
Successfully uninstalled pip-22.0.4
Successfully installed pip-22.0.4 wheel-0.37.1
C:\Users\WWKJ>pip show pip
Name: pip
Version: 22.0.4
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: distutils-sig@python.org
License: MIT
Location: d:\environmental\python\lib\site-packages
Requires:
Required-by:
pip安装selenium
安装
pip install selenium
查看安装的selenium版本
pip show selenium
查看安装的selenium版本
pip uninstall selenium
安装浏览器的驱动
已chrome为例
获取chrome的版本号
浏览器访问
chrome://version/
Google Chrome 99.0.4844.84 (正式版本) (64 位) (cohort: 99_Win_84)
修订版本 81a11fc2ee8a41e17451f29195387f276d3bb379-refs/branch-heads/4844_74@{#6}
操作系统 Windows 10 Version 1809 (Build 17763.2686)
JavaScript V8 9.9.115.10
用户代理 Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36
命令行 "C:\Program Files\Google\Chrome\Application\chrome.exe" --flag-switches-begin --flag-switches-end --flag-switches-begin --flag-switches-end
可以看到我用的浏览器版本为:99.0.4844.84
下载驱动
https://registry.npmmirror.com/binary.html?path=chromedriver/
点击下方99.0.4844.51的版本号(最好是版本号一致),下载适合自己电脑的驱动,并将下载的驱动解压到自己的python环境的路径中
源码
from selenium import webdriver
from selenium.webdriver.common.by import By
url="http://xxxx:8000/"
username="xx"
password="xxx"
chrome_driver="C:\Program Files\Google\Chrome\Application\chrome.exe"
driver = webdriver.Chrome(executable_path="chromedriver")
driver.set_window_size(1480,800)
driver.get(url)
driver.implicitly_wait(5)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/main/div[1]/div/form/div[1]/div/div/input").send_keys(username)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/main/div[1]/div/form/div[2]/div/div/input").send_keys(password)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/main/div[1]/div/form/div[4]/div/button[1]").click()
driver.implicitly_wait(5)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/section/aside/ul/div[1]/li[7]/div/span").click()
driver.implicitly_wait(5)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/section/aside/ul/div[1]/li[7]/ul/li/ul/li[2]/span").click()
driver.implicitly_wait(5)
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/section/main/div/div[2]/form/div[2]/div[3]/div/div/div/input[1]").send_keys("2022-03-22 10:10:10")
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/section/main/div/div[2]/form/div[2]/div[3]/div/div/div/input[2]").send_keys("2022-03-25 20:20:10")
driver.find_element(by=By.XPATH,value="/html/body/div[1]/div/section/section/main/div/div[2]/form/div[2]/div[4]/button[3]").click()
driver.implicitly_wait(10)
driver.find_element(by=By.CSS_SELECTOR,value="body > div.el-message-box__wrapper > div > div.el-message-box__btns > button.el-button.el-button--default.el-button--small.el-button--primary").click()
print("导出成功")
注意:本文归作者所有,未经作者允许,不得转载