def firefox_get_cookies(url): """ :param url: 请求连接 :return: """ c_service = Service('geckodriver') driver = any try: c_service.command_line_args() c_service.start() firefox_options = Options() # 不启动界面显示- linux下命令行模式必须启用 firefox_options.add_argument('-headless') driver = Firefox(options=firefox_options) driver.get(url) # 第一次请求浏览器一般无法显示cookie # 等待第一次加载完成 time.sleep(2) # 刷新 driver.refresh() # 等待第二次加载完成 time.sleep(2) return driver.get_cookies() except Exception as e: print(e) finally: driver.quit() c_service.stop()
def test_command_line_args(): service = Service("geckodriver", service_args=["--log", "trace"]) found = False args = service.command_line_args() for idx in range(len(args) - 1): if args[idx] == "--log" and args[idx + 1] == "trace": found = True break assert found, "Provided arguments do not exist in array"