• 安装selenium


    Python 3.7.4安装
    1.cmd
    2.pip3 install selenium --default-timeout=1000 -i https://pypi.tuna.tsinghua.edu.cn/simple

      

      

    安装selenium  需要依赖 webdriver

    安装与浏览器版本匹配的webdriver
    1、打开谷歌浏览器, 在地址栏输入 chrome://version/ 查看版本信息:
    假设您有Chrome 72.0.3626.81。
    获取Chrome版本号,删除最后一部分,然后将结果附加到网址“ https://chromedriver.storage.googleapis.com/LATEST_RELEASE_”。
    例如,在Chrome版本72.0.3626.81中,您将获得一个网址“ 百度https://chromedriver.storage.googleapis.com/LATEST_RELEASE_72.0.3626”。
    访问该网站即可获得对应版本的提示
    
    2、选择合适版本的驱动下载,
    下载地址:http://chromedriver.storage.googleapis.com/index.html
    
    3.将chromedriver.exe 放入安装的python的script目录下
    我的放在:C:softwarecomputerpythonpython37Scripts
    将C:softwarecomputerpythonpython37与C:softwarecomputerpythonpython37Scripts加入环境变量

    python目录下的script>右击鼠标+shift,打开cmd命令,执行下面代码 python import selenium from selenium import webdriver s=webdriver.Chrome() 如果弹出谷歌浏览器,表示成功

      

    小测试,登录QQ邮箱:

    # -*- coding:utf-8 -*-
    from selenium import webdriver
    import time
    
    username = ""  # QQ邮箱用户名
    password = ""  # QQ邮箱密码
    
    '''
    模拟登录qq邮箱
    '''
    # 打开浏览器
    wd = webdriver.Chrome()
    # 隐式等待时间
    wd.implicitly_wait(10)
    # 打开QQ邮箱地址
    wd.get("https://mail.qq.com")
    # 调整窗口大小
    wd.set_window_size(816, 230)
    
    # 切换iframe
    login_iframe = wd.find_element_by_id("login_frame")
    wd.switch_to.frame(login_iframe)
    # 点击帐号密码登录
    # wd.find_element_by_id("switcher_plogin").click()
    
    # 添加帐号和密码
    wd.find_element_by_id("u").send_keys(username)
    wd.find_element_by_id("p").send_keys(password)
    
    # 点击登录
    wd.find_element_by_id("login_button").click()
    

      

  • 相关阅读:
    such用法
    divorce用法
    towel用法
    go for用法
    catch on用法
    incredibly用法
    mess用法
    dentist用法
    steer clear of用法
    incredible
  • 原文地址:https://www.cnblogs.com/chargeworld/p/12288952.html
Copyright © 2020-2023  润新知