【发布时间】:2021-06-30 21:19:48
【问题描述】:
我正在尝试制作一个 instagram 机器人来使用 selenium 对提要中的每个帖子发表评论。到目前为止,它出现在一个帖子上,仅此而已。似乎每个帖子都有自己的评论部分。单个帖子的 html 是这样的:
如何让它对每条帖子发表评论?这是我目前用于评论的代码。
commentSection = ui.WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.Ypffh")))
self.driver.execute_script("arguments[0].scrollIntoView(true);", commentSection)
commentSection = ui.WebDriverWait(self.driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "textarea.Ypffh")))
commentSection.send_keys('yo')
self.driver.execute_script("window.scrollBy(0,-200)", "")
self.driver.find_element_by_xpath("//button[@type=\"submit\"]").click()
sleep(2)
【问题讨论】:
标签: python selenium browser-automation