[英]Infinite Scroll on Quora using Selenium in Python and Javascript
[英]Extract “(more)” text with Selenium from Quora - Python
我正试图抓住Quora的答案。 考虑此链接,例如: https : //www.quora.com/Is-it-too-late-for-an-X-year-old-to-learn-how-to-program
看第一个答案,有一个“更多”标签女巫表示存在更多隐藏的文字。
问题在Python中使用Selenium我无法打开并从此项中提取文本。
我尝试...我也尝试用JavaScript点击链接“显示更多”这个结构:
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")]')
这适用于“更多”的答案因为我用来从任何答案中提取文本的容器是相同的。
单击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)
9642
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.