安装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:\software\computer\python\python37\Scripts 将C:\software\computer\python\python37与C:\software\computer\python\python37\Scripts加入环境变量
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()

浙公网安备 33010602011771号