简体   繁体   English

无法使用硒javascript获取Div的全文(至页面末尾)

[英]Not Able to get full text(Till End of Page) of Div using selenium javascript

        List <WebElement> divList = driver.findElements(By.cssSelector("#graphiql-container > div.editorWrap > div.editorBar > div.resultWrap > div > div > div.CodeMirror-scroll"));
        List<WebElement> elements= driver.findElement(By.cssSelector(
                "#graphiql-container > div.editorWrap > div.editorBar > div.resultWrap > div > div > div.CodeMirror-scroll"))
                .findElements(By.xpath(".//*"));
        for (WebElement webElement : elements) {
            System.out.println(webElement.getText());
        }

I am using above code to get the entire text of particular div, however the string here return only visible text,however there is still more data till the end of page , it does not return it. 我正在使用上面的代码来获取特定div的整个文本,但是这里的字符串仅返回可见文本,但是直到页面末尾还有更多数据,它不会返回。 Is there any way we can achieve it ?. 有什么方法可以实现? Putting in a nutshell i want to get full text of specific section of webpage till the end. 简而言之,我想获得网页特定部分的全文,直到最后。

Here is my recently finished Java HTML Scrape Package. 这是我最近完成的Java HTML Scrape软件包。 Note, this is not javascript, but java. 注意,这不是javascript,而是java。

http://developer.torello.directory/JavaHTML/index.html http://developer.torello.directory/JavaHTML/index.html

This provides a really simple way to interact with HTML pages that are "Content Driven" on a website. 这提供了一种非常简单的方法来与网站上“内容驱动”的HTML页面进行交互。 Uses Regular Expressions to convert Raw-HTML into a simple java Vector. 使用正则表达式将Raw-HTML转换为简单的Java Vector。

To get the "Text" of any "DIV" node in an HTML-page. 获取HTML页面中任何“ DIV”节点的“文本”。

import Torello.HTML.*;

public class Scrape
{
  public static void main(String[] argv) throws IOException
  {
    Vector<HTMLNode> page = HTMLPage.getPageTokens(new java.net.URL("Your-URL"), false);
    int pos = InnerTagFind.first(page, "div", "class", TextTester.EQ, "div-class-constraint");
    HTMLNode n;
    // This will print all Text that follows the particular HTML <DIV CLASS="...">
    // View the scrape class documentation for other functions.
    for (int i=pos; i < page.size(); i++)
      if ((n = page.elementAt(i)) instanceof TextNode)
        System.out.println(n.str);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM