简体   繁体   中英

python - Selenium Stackoverflow Bot

Yesterday, I developed a Python Selenium Stackoverflow bot. The code was fine, It did not work though. This bot works with Selenium send_keys and driver.find_element_by_id . The code I developed is simple. It asks for the user's input.

It asks:

What's the bot email:
What's the bot password:
What's the Chatroom ID:

The code is below:

import unittest
from selenium import webdriver
import selenium, time

email = input("Enter bot Email: ")
password = input("Enter bot Password: ")
chatroom = input("Enter Chatroom ID: ")

driver = webdriver.Chrome()
emailin = driver.get('https://stackoverflow.com/users/login')

send_button = "sayit-button"

emai = driver.find_element_by_id('email')
emai.send_keys(email)
passw = driver.find_element_by_id('password')
passw.send_keys(password)
login_button = driver.find_element_by_name('submit-button')
login_button.click()
time.sleep()
driver.get('https://chat.stackoverflow.com/rooms/' + chatroom)

## commands
prefix = "/"
if driver.find_element_by_id('bubble') == f"{prefix}help":
  print(f"Command Uses in Chatroom")
  text = driver.find_element_by_id('input')
  text.send_keys('Hello! Im a Bot developed from Pytostack!')
  text.send_keys('My commands are `/help`.')
  send_button.click()
else:
  print(" ")

Yet it sends me this error from the terminal:

在此处输入图像描述

How could I fix this?

You need to get a chromedriver.exe to start with. Be sure to check your Chrome version and get the correspondent chromedriver. Then pass it to webdriver

chromedriver_path = 'your_path'
driver = webdriver.Chrome(executable_path=chromedriver_path)

The problem seems to start at Line # 9

driver = webdriver.Chrome()

I think you have problem when starting a browser instance, maybe permission change on your browser would help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM