我在试着抓取Quora的答案。考虑到这个链接,例如:https://www.quora.com/Is-it-too-late-for-an-X-year-old-to-learn-how-to-program
看第一个答案,有一个“更多”的标签女巫表示有更多的文本隐藏。
问题--使用中的Selenium --我无法打开并从这个项目中提取文本。
--我试着.--我也试着用JavaScript点击链接"Show“,用这个结构:
try:
if ans.find_element_by_xpath('.//a[contains(@class, "more_link")]').is_displayed():
elem_more = ans.find_element_by_xpath('.//a[contains(@class, "more_link")]')
#self.driver.execute_script("arguments[0].click();", elem_more )
Hover = webdriver.ActionChains(self.driver).move_to_element(elem_more)
Hover.click(elem_more).perform()
#wait_1.until(EC.invisibility_of_element_located((By.CLASS_NAME, "switch_indicator")))
except (NoSuchElementException,TimeoutException) as e:
pass然后把答案的内容
content = ans.find_element_by_xpath('.//span[contains(@class, "inline_editor_value")]')这与回答“更多”是一样的,因为我用来从任何答案中提取文本的容器。

发布于 2015-10-13 16:30:48
单击more按钮后,可以获得css路径'.inline_editor_value > div > div'中的整篇文章。
>>> c = driver.find_element_by_css_selector('.inline_editor_value > div > div').text
>>> print len(c)
3491
>>> driver.find_element_by_class_name("more_link").click()
>>> c_new = driver.find_element_by_css_selector('.inline_editor_value > div > div').text
>>> print len(c_new)
9642https://stackoverflow.com/questions/33107090
复制相似问题