全站数据
8 4 2 0 5 8 1

如何用python模拟点击onclick

三期工程 | 简单学习,快乐成才!         
问题更新日期:2024-10-14 15:38:44

问题描述

如何用python模拟点击onclick,麻烦给回复
精选答案
最佳答案

先在命令行中下载一个selenium库:

python -m pip install selenium

然后使用selenium中的webdriver来进行模拟网页点击:

from selenium import webdriver

from selenium.common.exceptions import TimeoutException

from selenium.webdriver.chrome.options import Options

from selenium.webdriver.support.ui import Select

from selenium.webdriver.support.ui import WebDriverWait

sel=webdriver.Chrome() #也可换成Ie(),Firefox()等

element=sel.find_element() #在网页源码中查找元素,具体可参考

http://www.aichengxu.com/python/11949.htm

element.click() #模拟对元素进行点击

如果你是Chrome用户,需要手动下载一个chromedriver.exe,这里附上,把它放入系统Path路径任意一个文件夹中即可