问题内容 我有这个代码: from selenium import WEBdriver from selenium.webdriver.chrome.service import se
我有这个代码:
from selenium import WEBdriver
from selenium.webdriver.chrome.service import service
from time import sleep
# create a service object by specifying the path to chromedriver
chrome_service = service(executable_path="path\crome.exe")
options = webdriver.chromeoptions()
options.add_argument("user-data-dir=c:\\path_file")
# pass the service object to webdriver.chrome()
driver = webdriver.chrome(service=chrome_service, options=options)
# open whatsapp web
driver.get("https://web.whatsapp.com/")
sleep(10)
当我运行此代码时,chrome 浏览器会打开,但 whatsapp 网页不会打开。如何解决这个问题?
我尝试使用几种不同的方法,例如:
from webdriver_manager.chrome import chromedrivermanager
driver = webdriver.chrome(chromedrivermanager().install())
和:
options.add_argument("user-agent=Mozilla/5.0 (windows NT 10.0; Win64; x64) AppleWebKit/537.36 (Khtml, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
但是没有一个起作用
您不再需要指定 chrome 可执行路径。安装 chrome 并将其设置为默认浏览器就足够了。
我测试了这个,它工作正常:
from selenium import webdriver
from time import sleep
options = webdriver.ChromeOptions()
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
#options.add_argument("user-data-dir=C:\\path_file")
# Pass the Service object to webdriver.Chrome()
driver = webdriver.Chrome(options=options)
# Open WhatsApp Web
driver.get("Https://web.whatsapp.com/")
sleep(10)
以上就是selenium webdriver 打开chrome但打不开whatsappWeb的详细内容,更多请关注编程网其它相关文章!
--结束END--
本文标题: selenium webdriver 打开chrome但打不开whatsappWeb
本文链接: https://www.lsjlt.com/news/562182.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0