Python Selenium 打开 Whatsapp,无需每次都使用二维码

问题描述 投票:0回答:1
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
from selenium.webdriver.chrome.service import Service
from config import CHROME_DATA_PATH

option = webdriver.ChromeOptions()
option.add_argument(CHROME_DATA_PATH)


driver = webdriver.Chrome(service = Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://web.whatsapp.com/")

time.sleep(10)
driver.quit()

我一直在尝试使用selenium 制作一个WhatsApp 机器人。我几乎尝试了所有方法来打开 WhatsApp,每次都不需要使用二维码。但我不明白为什么它不起作用。大多数解决方案都是通过executable_path方法编写的,该方法目前不起作用。

我也尝试过通过打开特定的浏览器来使用它。但后来我遇到了一个错误:

C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed
python selenium-webdriver selenium-chromedriver whatsapp
1个回答
0
投票
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

option = webdriver.ChromeOptions()
option.add_argument(r"user-data-dir=C:\Users\username\AppData\Local\Google\Chrome\Profile 1")
chrome_service = Service(executable_path = r'chromedriver.exe')

driver = webdriver.Chrome(service = chrome_service, options = option)
driver.get("https://web.whatsapp.com/")
driver.implicitly_wait(30)
time.sleep(20)

使用代码登录您的 Whatsapp 帐户后,您的登录数据将自动保存到 AppData。您应该使用 chromedriver,以便程序可以将数据保存到其中。

© www.soinside.com 2019 - 2024. All rights reserved.