让 Whatsapp Web 不需要 QR 扫描
Making Whatsapp Web not needing QR-scanning
我一直致力于使用 selenium 制作 WhatsApp 机器人,但每次我 运行 我的代码都必须重新扫描二维码才能输入。我在 youtube 视频中找到了此解决方案以使用选项,但它不起作用并且 returns 出现错误 selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
这是我的代码
from selenium import webdriver
import time
if __name__ == '__main__':
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\Hill\AppData\Local\Google\Chrome\User Data\Default')
options.add_argument(r'--profile-directory=Default')
driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', chrome_options=options)
driver.get('https://web.whatsapp.com')
time.sleep(15)
您基本上是在给 Chrome-Browser 两个配置文件。第一个是您的个人资料,第二个是默认个人资料。以下步骤对我有用:
手动打开 Chrome 并转到 https://web.whatsapp.com,然后扫描 QR-Code。关闭一切并实现以下代码(请删除您实现中的注释,因为它们的语法会导致问题;-)):
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\Hill\AppData\Local\Google\Chrome\User Data\') #here is no <Default>!!
driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', options=options) #selenium 4 preferes "options" -> your code is more up to date :-)
driver.get('https://web.whatsapp.com')
time.sleep(15)
我一直致力于使用 selenium 制作 WhatsApp 机器人,但每次我 运行 我的代码都必须重新扫描二维码才能输入。我在 youtube 视频中找到了此解决方案以使用选项,但它不起作用并且 returns 出现错误 selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
这是我的代码
from selenium import webdriver
import time
if __name__ == '__main__':
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\Hill\AppData\Local\Google\Chrome\User Data\Default')
options.add_argument(r'--profile-directory=Default')
driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', chrome_options=options)
driver.get('https://web.whatsapp.com')
time.sleep(15)
您基本上是在给 Chrome-Browser 两个配置文件。第一个是您的个人资料,第二个是默认个人资料。以下步骤对我有用: 手动打开 Chrome 并转到 https://web.whatsapp.com,然后扫描 QR-Code。关闭一切并实现以下代码(请删除您实现中的注释,因为它们的语法会导致问题;-)):
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\Hill\AppData\Local\Google\Chrome\User Data\') #here is no <Default>!!
driver = webdriver.Chrome(executable_path=r'C:\Program Files (x86)\chromedriver.exe', options=options) #selenium 4 preferes "options" -> your code is more up to date :-)
driver.get('https://web.whatsapp.com')
time.sleep(15)