python+selenium(python开发)

准备:python +selenium + chromedriver
1.下载chromedriver 要兼容本地的chrome 
  对应版本号 https://chromedriver.storage.googleapis.com/2.36/notes.txt
  chromedriver下载地址 :https://chromedriver.storage.googleapis.com/index.html?path=2.35/
2.系统上要有python开发环境(如anaconda)
安装selenium 在python命令提示下运行: pip install selenium 
将自动安装最新版的selenium

简单Demo:
# encoding=utf8

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import time

# 前台开启浏览器模式
def openChrome():
    # 加启动配置
    option = webdriver.ChromeOptions()
    option.add_argument('disable-infobars')
    # 打开chrome浏览器
    driver = webdriver.Chrome(chrome_options=option)
    return drivers

# 授权操作
def operationAuth(driver):
    url = "http://www.baidu.com"
    driver.get(url)
    # 找到输入框并输入查询内容
    elem = driver.find_element_by_id("kw")
    elem.send_keys("selenium")
    # 提交表单
    driver.find_element_by_xpath("//*[@id='su']").click()

    print('查询操作完毕!')

# 方法主入口
if __name__ == '__main__':
    # 加启动配置
    driver = openChrome()
    operationAuth(driver)

猜你喜欢

转载自blog.csdn.net/qq_41444640/article/details/81739957