用selenium控制已打开的浏览器

2020-04-20  本文已影响0人  文知道

用selenium控制已打开的浏览器

cd C:\Program Files (x86)\Google\Chrome\Application
chrome.exe --remote-debugging-port=9222 --user-data-dir="C:\Program Files (x86)\Google\Chrome\Application\selenium\AutomationProfile"
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver = "d:\python_tool\chromedriver.exe"
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
print(driver.title)

mac版

下载ChromeDriver http://npm.taobao.org/mirrors/chromedriver/
解压后将chromedriver复制到 /usr/local/bin/ 下

/Applications/Chrome2.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir="/Users/bin/Documents/project/chrome2"
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
chrome_driver = "/usr/local/bin/chromedriver"
browser = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
上一篇下一篇

猜你喜欢

热点阅读