我在使用 Jsoup 时遇到问题 tJavaRow Talend 中的组件。

这是我的工作:

Job Layout

通过 tLibraryLoad 我加载 .jar Jsoup 和 java.io.File 库的文件,然后将它们导入到 tJavaRow_2 成分:

import java.io.File;
import java.io.File;
import org.jsoup.Jsoup;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import org.jsoup.select.Elements;

然后尝试在主要部分运行以下代码 tJavaRow_2:

Document document = Jsoup.parse(new File("C:/Talend/workspace/WEBCRAWLER/output/keywords_" + context.keywordname +".txt", "utf-8");
Document document = Jsoup.parse(new File("C:/Talend/workspace/WEBCRAWLER/output/keywords_" + context.keywordname +".txt", "utf-8");
        Elements el = document.select(".gutter10");
        Elements el = document.select(".gutter10");
        String result = el.text();
        String result = el.text();


        if(result.length() > 20)
        if(result.length() > 20)
            {context.lastpage = true;};

到目前为止对我来说似乎是合乎逻辑的。但我收到这个错误:

Talend Error

你能帮我解决这个问题吗?我不明白从现在开始该怎么办。

附录: :在 Eclipse 中运行的 Java 代码:

import java.io.File;
import java.io.File;
//import java.util.regex.*;
import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

public class regextest  {

    public static boolean regExChecker() throws IOException 
    {
        boolean x = false;
        Document document = Jsoup.parse(new File("C:/Talend/workspace/WEBCRAWLER/output/absolventa_testquery.txt"), "utf-8");
        Elements el = document.select(".gutter10");
        String result = el.text();

        if(result.length() > 20)
            {x = true;};

        //System.out.println(x);
        return x;
    }

    public static void main(String[] args) throws IOException{
        System.out.println(regExChecker()); 
    }
}
有帮助吗?

解决方案

您的代码块中缺少右括号。你的第一行应该是:

Document document = Jsoup.parse(new File("C:/Talend/workspace/WEBCRAWLER/output/keywords_" + context.keywordname +".txt"), "utf-8");

事实上,您正在从路径构建一个文件 "C:/Talend/workspace/WEBCRAWLER/output/keywords_" + context.keywordname +".txt"), "utf-8" 然后将该文件对象(它不是一个正确的文件对象,但由于某种原因编译器没有发现这一点)传递给 Jsoup 的 parse 方法。

看着 Jsoup 的文档 解析单个值的唯一方法调用是当您将字符串中的 HTML 文档传递给它时。因此它需要一个字符串,但却得到一个(损坏的)文件。

第二个错误真正指出了这一点,它指出您缺少 VariableInitializer 的右括号。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top