我的电脑上的chrome自动更新到最新版本,再从https://googlechromelabs.github.io/chrome-for-testing/#stable \处下载稳定版chromedriver程序,稳定版和最新版本的版本号接近。chromedriver.exe放在chrome程序的工作目录下,再在脚本里面指明chromedriver.exe的路径。
没有input()阻塞,浏览器访问网站十秒后就关闭窗口了。
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.service import Service
class Body():
def __init__(self):
self.options = webdriver.ChromeOptions()
self.options.add_argument('disable-infobars')
self.options.add_experimental_option("excludeSwitches", ['enable-automation'])
self.options.add_argument('--disable-blink-features')
self.options.add_argument('--disable-blink-features=AutomationControlled')
self.options.add_argument('--disable-gpu')
#chromedriver路径
service = Service('C:/Program Files/Google/Chrome/Application/chromedriver.exe')
self.browser = webdriver.Chrome(service=service, options=self.options)
self.browser.maximize_window()
self.browser.implicitly_wait(5)
self.action_chains = ActionChains(self.browser)
def do(self):
ls=['https://taobao.com','https://baidu.com']
self.browser.get(ls[0])
driver_wait = WebDriverWait(self.browser, 10)
for i in ls[1:]:
newTab=f'window.open("{i}")'
self.browser.execute_script(newTab)
input()
if __name__ == '__main__':
b = Body()
b.do()
Python之selenium创建多个标签页 https://www.cnblogs.com/mafu/p/14158337.html
python实现自动登录淘宝 https://www.cnblogs.com/Vena/p/18435295
Selenium + Python 之 WebDriver 驱动下载与使用 https://www.cnblogs.com/sunisnyu/p/18442541
创建于2410042057,修改于2410042057
标签:__,标签,self,selenium,访问,https,options,browser From: https://www.cnblogs.com/tellw/p/18447258