Example #1
0
def livefyreComments(driver):
  """Extract comments from LiveFyre if present. Clicks on the "load-more"
  button while its visible to load all comments.

  @type  driver: selenium.webdriver.phantomjs.webdriver.WebDriver
  @param driver: the driver
  @rtype: tuple of CommentItem
  @return: the extracted comments
  """
  try:
    driver.find_element_by_xpath("//*[@id='livefyre']")
  except NoSuchElementException:
    return tuple()

  sleep(2)
  clickWhileVisible(driver, "//*[@class='fyre-stream-more-container']")
  sleep(2)
  return extractComments(
    driver=driver,
    commentXP=xPathWithClass("fyre-comment-article"),
    contentXP="." + xPathWithClass("fyre-comment"),
    authorXP="." + xPathWithClass("fyre-comment-username") + "//text()",
    publishedXP="." + xPathWithClass("fyre-comment-date") + "//text()")
Example #2
0
def disqusComments(driver):
  """Extract comments from Disqus if present. Clicks on the "load-more" button
  while its visible to load all comments.

  @type  driver: selenium.webdriver.phantomjs.webdriver.WebDriver
  @param driver: the driver
  @rtype: tuple of CommentItem
  @return: the extracted comments
  """
  try:
    iframe = driver.find_element_by_xpath("//*[@id='dsq2']")
  except NoSuchElementException:
    return tuple()

  driver.switch_to_frame(iframe)
  sleep(0.2)
  clickWhileVisible(driver, xPathWithClass("load-more") + "/a")
  return extractComments(
    driver=driver,
    commentXP=xPathWithClass("post"),
    contentXP="." + xPathWithClass("post-message"),
    authorXP="." + xPathWithClass("author") + "//text()",
    publishedXP="." + xPathWithClass("post-meta") + "/a/@title")