Python 含硒网格的selenium whatsapp机器人

Python 含硒网格的selenium whatsapp机器人,python,selenium,bots,whatsapp,Python,Selenium,Bots,Whatsapp,我正在尝试使用selenium网格远程web驱动程序创建一个WhatsApp机器人。我在读取二维码时遇到问题,驾驶员未打开,因此二维码未被扫描 远程驱动程序代码: def get_remote_driver(): options = webdriver.ChromeOptions() options.add_argument(r"user-data-dir=C:\Users\97254\PycharmProjects\BotForHadas\Data\QR") options

我正在尝试使用selenium网格远程web驱动程序创建一个WhatsApp机器人。我在读取二维码时遇到问题,驾驶员未打开,因此二维码未被扫描

远程驱动程序代码:

def get_remote_driver():
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\97254\PycharmProjects\BotForHadas\Data\QR")
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.set_headless()
Capabilities = options.to_capabilities()

driver = webdriver.Remote(
command_executor=f"http://10.100.102.15:4444/wd/hub",
desired_capabilities=Capabilities
)
return driver

driver = get_remote_driver()
driver.get("http://web.whatsapp.com/")
driver.maximize_window()
print("Loading Site")
time.sleep(1)
print("Current Site " + driver.title)
bot = WhatsappBot.bot(driver)
print("Scanning QR Code")
wait = WebDriverWait(driver, 50)
element = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="side"]/header/div[1]/div')))
print("Logged In")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(r"user-data-dir=C:\Users\97254\PycharmProjects\BotForHadas\Data\QR")
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
# Chrome Visible or not
# chrome_options.add_argument("headless")
driver = webdriver.Chrome('chromedriver_win32/chromedriver.exe', options=chrome_options)
driver.get("http://web.whatsapp.com/")

bot = WhatsappBot.bot(driver)
print("Scanning QR Code")
wait = WebDriverWait(driver, 50)
element = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="side"]/header/div[1]/div')))
print("Logged In")
在此代码中,驾驶员未打开且二维码无法扫描此行打印(“扫描二维码”)正在执行,而此行打印(“登录”)未执行

正常驾驶员代码:

def get_remote_driver():
options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\97254\PycharmProjects\BotForHadas\Data\QR")
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.set_headless()
Capabilities = options.to_capabilities()

driver = webdriver.Remote(
command_executor=f"http://10.100.102.15:4444/wd/hub",
desired_capabilities=Capabilities
)
return driver

driver = get_remote_driver()
driver.get("http://web.whatsapp.com/")
driver.maximize_window()
print("Loading Site")
time.sleep(1)
print("Current Site " + driver.title)
bot = WhatsappBot.bot(driver)
print("Scanning QR Code")
wait = WebDriverWait(driver, 50)
element = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="side"]/header/div[1]/div')))
print("Logged In")
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(r"user-data-dir=C:\Users\97254\PycharmProjects\BotForHadas\Data\QR")
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
# Chrome Visible or not
# chrome_options.add_argument("headless")
driver = webdriver.Chrome('chromedriver_win32/chromedriver.exe', options=chrome_options)
driver.get("http://web.whatsapp.com/")

bot = WhatsappBot.bot(driver)
print("Scanning QR Code")
wait = WebDriverWait(driver, 50)
element = wait.until(EC.presence_of_element_located((By.XPATH, '//*[@id="side"]/header/div[1]/div')))
print("Logged In")
在该代码中,驱动程序处于打开状态,二维码被扫描。执行该行打印(“登录”)

请帮帮我