- 安裝selenium
pip install selenium
2.安裝Chrome driver
下載解壓,你會(huì)得到一個(gè)chromedriver.exe文件,需要把這家伙放到chrome的安裝目錄下...\Google\Chrome\Application\ ,然后設(shè)置path環(huán)境變量,把chrome的安裝目錄(我的:C:\Program Files\Google\Chrome\Application)加進(jìn)去
下載鏈接[http://chromedriver.chromium.org/getting-started]
#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
import time
import os
profile_dir=r"C:\Users\yan\AppData\Local\Google\Chrome\User Data" # 對(duì)應(yīng)你的chrome的用戶(hù)數(shù)據(jù)存放路徑
chrome_options=webdriver.ChromeOptions()
chrome_options.add_argument("user-data-dir="+os.path.abspath(profile_dir))
browser=webdriver.Chrome(chrome_options=chrome_options)
browser.maximize_window()
browser.get("http://www.baidu.com")