Python3.5+selenium操作Chrome瀏覽器


1.安裝selenium

命令提示符下輸入:
pip install selenium

2.下載chromedriver

點擊下載

3.將解壓后的chromedriver.exe放到chrome瀏覽器的安裝目錄下。

4.實例

復制代碼
from selenium import webdriver  
import os
#引入chromedriver.exe
chromedriver = "C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chromedriver)

#設置瀏覽器需要打開的url url = "http://www.baidu.com" browser.get(url)
#在百度搜索框中輸入關鍵字"python" browser.find_element_by_id("kw").send_keys("python")
#單擊搜索按鈕 browser.find_element_by_id("su").click()

#關閉瀏覽器
#browser.quit()
復制代碼


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM