【问题标题】:Python Webdriver Unable to locate the xpath in facebook for Liked button in pagesPython Webdriver 无法在 facebook 中为页面中的 Liked 按钮找到 xpath
【发布时间】:2017-04-11 12:31:50
【问题描述】:

Need xpath of "Liked" button(Image attached here)

我尝试了这些,但出现错误。

driver.find_element_by_xpath(".//button[contains(text(), 'Liked'").click()

driver.find_element_by_xpath(".//button[contains(text(), 'Liked'").send_keys(Keys.RETURN)

【问题讨论】:

  • 分享喜欢按钮的html。 FB 限制在我的办公室 :(
  • Html 在这里共享。 @ShoaibAkhtar pastebin.com/BbsqZi91
  • 为什么首先需要使用 selenium 与 Like 按钮进行交互?除了创建虚假喜欢之外,我看不出这有什么用。
  • 不是为了创造假喜欢。我只是在为 不喜欢 页面编写脚本。

标签: python facebook selenium xpath webdriver


【解决方案1】:
driver.find_elements_by_xpath(".//button[contains(text(), 'Liked')]").click()

driver.find_elements_by_xpath(".//button[contains(text(), 'Liked')]").send_keys(Keys.RETURN)

你错过了括号。请尝试使用上面的 xpath。

您也可以尝试官方的facebbok api进行数据收集

【讨论】:

  • 出现错误。 selenium.common.exceptions.InvalidSelectorException: Message: Given xpath expression ".//button[contains(text(), 'Liked')" is invalid: SyntaxError: The expression is not a legal expression.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-26
  • 1970-01-01
  • 1970-01-01
  • 2014-06-15
  • 2013-01-21
  • 2014-06-21
相关资源
最近更新 更多