我使用python来实现测试。我需要保持登录过程,这样我就不会每次都登录。我使用add_argument(“--用户-数据-dir= chrome”)来保存铬数据,但是当我想使用无头模式时,保存的数据没有保持登录过程。
class Browser:
def __init__(self, headless):
self.chrome_options = webdriver.ChromeOptions()
self.chrome_options.headless = headless
self.chrome_options.add_argument('--hide-scrollbars')
self.chrome_options.add_argument('--disable-gpu')
self.chrome_options.add_argument("--log-level=3")
self.chrome_options.add_argument("--user-data-dir=chrome-data")
self.chrome_options.add_argument('profile-directory=profile')
self.chrome_options.add_experimental_option("detach", True)
self.driver = webdriver.Chrome(executable_path="./chromedriver", options=self.chrome_options)
self.driver.implicitly_wait(10)
self.driver.maximize_window()发布于 2022-05-01 15:34:35
使用无头铬时,一些网站会检测无头模式,防止自动上身。
将此添加到您的铬选项中
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36")这应该会改变您的用户代理,并且应该在autologin中提供帮助,如果问题仍然存在,您应该尝试指定默认的chrome配置文件目录。
self.chrome_options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profile你应该用这个
self.chrome_options.add_argument("--headless")https://stackoverflow.com/questions/72075183
复制相似问题