我正在尝试使用Selenium在subreddit上发布评论,但是在评论框中遇到了麻烦

时间:2020-09-07 16:08:17

标签: python python-3.x selenium-webdriver selenium-chromedriver reddit

我试图在reddit上发表评论,我能够登录并导航至所需链接。我在选择评论框并粘贴(发送键)我要发布的评论时遇到麻烦。有人可以帮我吗?

这是我到目前为止所拥有的:

#!/usr/bin/env python3
import sys
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Chrome()
driver.get("https://old.reddit.com/r/Python/comments/inbwja/sunday_megathread_whats_everyone_working_on_this/")
driver.set_window_size(2560, 988)
driver.find_element(By.NAME, "user").send_keys("myusername")
driver.find_element(By.NAME, "passwd").send_keys("mypassword")
driver.find_element(By.CLASS_NAME, "submit").click()
driver.find_element(By.XPATH, "/html/body/div[4]/div[2]/form/div/div[2]/textarea").send_keys("my comment")

我得到的错误如下:

Unable to locate element: {"method":"xpath","selector":"/html/body/div[4]/div[2]/form/div/div[1]/textarea"}
  (Session info: chrome=85.0.4183.83)

如何通过send_keys将评论传递到reddit中的评论框?

谢谢您的时间。

0 个答案:

没有答案