Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 摘录;(更多)“;来自Quora-Python的含Selenium的文本_Javascript_Python_Css_Selenium_Web Scraping - Fatal编程技术网

Javascript 摘录;(更多)“;来自Quora-Python的含Selenium的文本

Javascript 摘录;(更多)“;来自Quora-Python的含Selenium的文本,javascript,python,css,selenium,web-scraping,Javascript,Python,Css,Selenium,Web Scraping,我正在努力寻找答案。 例如,考虑到这一联系: 看第一个答案,有一个“更多”的标签,表明存在更多隐藏的文本 问题 在Python中使用Selenium,我无法打开和提取此项中的文本 我尝试… 我还尝试使用JavaScript点击“显示更多”链接,并使用以下指令: try: if ans.find_element_by_xpath('.//a[contains(@class, "more_link")]').is_displayed():

我正在努力寻找答案。 例如,考虑到这一联系:

看第一个答案,有一个“更多”的标签,表明存在更多隐藏的文本

问题 在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")]')
这适用于没有“更多”的答案,因为我使用的容器与从任何答案中提取文本的容器相同


单击
更多
按钮后,您可以看到整个文章都存在于这个css路径
'。内联编辑器\u 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

我尝试使用这个解决方案,但仍然不起作用。他不接受文本内容。我成功地做到了。检查shell输出。使代码比添加try块更简单。