2014-06-11 23 views
0

時,「找不到符號」我需要在html表中找到一個值,所以現在我試圖獲得JSoup的掛件。嘗試jsoup:當我剛剛聲明它爲

我試圖使用實現此代碼:http://jsoup.org/cookbook/extracting-data/dom-navigation

前兩行我已經實現,但第三個(元素含量= doc.getElementById(「內容」);)會導致「錯誤:找不到符號符號:變量DOC位置:類testparse)

這裏是我的代碼:!

import org.jsoup.*; 
import org.jsoup.nodes.*; 
import java.io.*; 


public class testparse { 
    public static void main(String[] args){ 
    try 
    { 
    File input = new File("abc.htm"); 
    Document doc = Jsoup.parse(input, "UTF-8", ""); 
    } 
    catch(IOException exc){ 
     System.out.println(exc); 
    } 


    Element content = doc.getElementById("content"); 


    } 
} 

所有幫助是極大的讚賞

+1

查找到可變範圍。 –

回答

0

變量的範圍是在try塊內:

try 
{ 
    File input = new File("abc.htm"); 
    Document doc = Jsoup.parse(input, "UTF-8", ""); 
} 

要修復,外聲明變量:

File input = null; 
Document doc = null; 

try 
{ 
    input = new File("abc.htm"); 
    doc = Jsoup.parse(input, "UTF-8", ""); 
} 
相關問題