最近在学习使用selenium,踩了很多坑,主要集中在导入Options报错,版本如下:
Python 3.11.5
Name: selenium
Version: 4.11.2
Summary:
Home-page: https://www.selenium.dev
Author:
Author-email:
License: Apache 2.0
Location: C:\Python311\Lib\site-packages
Requires: certifi, trio, trio-websocket, urllib3
Required-by: selenium-wire
分享和记录现在能用的设置:
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
from selenium.common.exceptions import NoSuchElementException
hide_windown = 0 #0不隐藏,1隐藏
options = Options()
if hide_windown == 1:
options.add_argument('--headless') #增加无界面选项
options.page_load_strategy = 'normal'#等待加载图片normal eager none
else:
options.page_load_strategy = 'eager'#不等待加载图片normal eager none
opt