-
Notifications
You must be signed in to change notification settings - Fork 70
无法登录deepl #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
感谢反馈该问题,这确实是一个已知的问题。原因应该出在cloudflare的验证机制对playwright的webdriver的特征检测上。对于playwright的webkit内核,也就是目前默认的方法上,没有特别好的解决办法,因为那个内核是微软高度定制的很难绕过自动化特征检测,playwright本身对反爬虫检测的手段相比其他自动化测试软件如selenium等也少一些。 # 构建 Edge 默认用户数据目录路径
username = os.getlogin()
if os.name == 'nt': # Windows
user_data_dir = fr"C:\Users\{username}\AppData\Local\Microsoft\Edge\User Data"
elif os.name == 'posix': # macOS/Linux
if 'darwin' in os.uname().sysname.lower(): # macOS
user_data_dir = f"/Users/{username}/Library/Application Support/Microsoft Edge"
else: # Linux
user_data_dir = f"/home/{username}/.config/microsoft-edge"
else:
raise OSError("Unsupported operating system")
if not os.path.exists(user_data_dir):
raise FileNotFoundError(f"用户数据目录不存在: {user_data_dir}")
subprocess.Popen([browser_executable_path, '--remote-debugging-port=9222', f'--user-data-dir={user_data_dir}'], shell = True)
with sync_playwright() as p:
# Launch the browser
print("正在拉起浏览器")
if Path(playwright_path).exists():
browser_executable_path = Path(playwright_path)
browser = p.webkit.launch(executable_path=browser_executable_path, headless=playwright_headless)
make_edge_happy = False
elif default_edge_path.exists():
print("未找到webikit内核,使用edge内核,但该模式可能兼容性有问题")
browser = p.chromium.connect_over_cdp('http://127.0.0.1:9222') # 连接到远程调试端口
context = browser.contexts[0] # 获取已有的上下文
make_edge_happy = True
else:
raise FileNotFoundError("找不到Playwright内核")
page = context.pages[0] 注意需要彻底关闭正在运行的edge才能生效。 |
好的,谢谢 |
The text was updated successfully, but these errors were encountered: