【问题标题】:Trying jsoup: getting "cannot find symbol" when I just declared it the line before尝试 jsoup:当我刚刚在前一行声明时得到“找不到符号”
【发布时间】:2014-06-11 22:34:55
【问题描述】:

我需要在 html 表中找到一个值,所以现在我正在尝试掌握 JSoup 的窍门。

我正在尝试使用实现此代码:http://jsoup.org/cookbook/extracting-data/dom-navigation

前两行我已经实现,但第三行 (Element content = doc.getElementById("content");) 导致“错误:找不到符号。符号:变量 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");


  }
}

非常感谢所有帮助!

【问题讨论】:

  • 查看变量范围。

标签: java html jsoup


【解决方案1】:

变量的作用域在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", "");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    • 1970-01-01
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    相关资源
    最近更新 更多