Selenium的使用,安装chromedriver

时间:2022-11-18 09:57:29


注意chrome和ChromeDriver版本对应

1、安装32位电脑版chrome

默认路径"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

2、下载好的chromedriver.exe直接拷贝到C:\Program Files (x86)\Google\Chrome\Application即可

3、设置环境变量

Selenium的使用,安装chromedriver


4、测试脚本

引用这本书里面的脚本

Selenium的使用,安装chromedriver

from selenium import webdriver
from lxml import etree
from pyquery import PyQuery as pq
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium. webdriver. support. wait import WebDriverWait
browser =webdriver. Chrome(executable_path="C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
try:
browser. get('https://www.baidu.com')
input=browser. find_element_by_id('kw')
input. send_keys('Python')
input. send_keys(Keys. ENTER)
wait=WebDriverWait(browser,10)
wait. until(EC. presence_of_element_located((By.ID,'content_left')))
print(browser. current_url)
print(browser. get_cookies())
print(browser. page_source)
finally:
browser. close()

Chrome32
链接:​​​https://pan.baidu.com/s/1OipptGfZ0kbCd3aUQRDHWg​​​ 提取码:peks
ChromeDriver
链接:​​https://pan.baidu.com/s/1-D3anT0nofxMRMU75EzUfw​​ 提取码:yy8a

添加两个链接方便查找
chrome
​​​https://pan.lanzou.com/b112274​​​ chromedriver
​http://chromedriver.storage.googleapis.com/index.html​