[英]Method not applicable error using Jsoup in custom Java code
我在Talend的tJavaRow
組件中使用Jsoup時遇到問題。
這是我的工作:
通過tLibraryLoad
我為Jsoup和java.io.File庫加載.jar
文件,然后將它們導入到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;};
到目前為止,對我來說似乎合乎邏輯。 但是我得到這個錯誤:
您能幫我解決這個問題嗎? 從那時起,我不知道該怎么辦。
附錄 :可在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"
,您正在從路徑"C:/Talend/workspace/WEBCRAWLER/output/keywords_" + context.keywordname +".txt"), "utf-8"
構建文件,然后僅傳遞該文件對象(它不是適當的文件對象,但由於某種原因,編譯器尚未發現該對象)使用Jsoup的parse方法。
查看Jsoup的文檔 ,唯一的解析方法調用是單個值是在字符串中傳遞HTML文檔時。 因此,它期望一個字符串,而是獲取一個(損壞的)文件。
第二個錯誤是通過指出您缺少VariableInitializer的右括號而真正指出這一點的錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.