Java使用Jsoup从网站读取信息

Java使用Jsoup从网站读取信息,java,parsing,jsoup,Java,Parsing,Jsoup,我已经阅读了多篇关于语法分析之类的文章。我看到的大多数回复都是建议此人使用图书馆或其他东西。我现在的问题是创建一个算法来获取我想要的准确信息。我这样做的目的是从天气网站获取2个学校关闭状态。我开始按照别人的建议使用Jsoup,但我需要帮助 网页: 图片: 网页来源示例: 我可能会想出如何在网页中获得某一行文字,因为我已经知道我要找的学校的名称,但向下两行是我需要的状态。如果每所学校都有特定的状态,那就很容易了,但它们要么都关闭了,要么都推迟了两个小时,所以我不能只是搜索。我想要一些关于如何实现这

我已经阅读了多篇关于语法分析之类的文章。我看到的大多数回复都是建议此人使用图书馆或其他东西。我现在的问题是创建一个算法来获取我想要的准确信息。我这样做的目的是从天气网站获取2个学校关闭状态。我开始按照别人的建议使用Jsoup,但我需要帮助

网页:

图片:

网页来源示例:

我可能会想出如何在网页中获得某一行文字,因为我已经知道我要找的学校的名称,但向下两行是我需要的状态。如果每所学校都有特定的状态,那就很容易了,但它们要么都关闭了,要么都推迟了两个小时,所以我不能只是搜索。我想要一些关于如何实现这一点的想法或答案。我打算这样做2次,因为我想查找2所学校。我已经有了我可以用来查找它们的名字,我只需要状态

下面是我想做的一个例子。(sudo代码)

这就是我现在拥有的

public static SchoolClosing lookupDebug() throws IOException {
        final ArrayList<String> Status = new ArrayList<String>();

        try {
            //connects to my wanted website
            Document doc = Jsoup.connect("http://www.10tv.com/content/sections/weather/closings.html").get();
            //selects/fetches the line of code I want
            Element schoolName = doc.html("<td valign="+"top"+">Athens City Schools</td>");
            //an array of Strings where I am going to add the text I need when I get it
            final ArrayList<String> temp = new ArrayList<String>();
            //checking if its fetching the text
            System.out.println(schoolName.text());
            //add the text to the array
            temp.add(schoolName.text());
            for (int i = 0; i <= 1; i++) {
                final String[] tempStatus = temp.get(i).split(" ");
                Status.add(tempStatus[0]);
            }
        } catch (final IOException e) {
            throw new IOException("There was a problem loading School Closing Status");
        }
        return new SchoolClosing(Status);
    }
publicstaticschoolookupdebug()引发IOException{
最终ArrayList状态=新建ArrayList();
试一试{
//连接到我的通缉网站
Document doc=Jsoup.connect(“http://www.10tv.com/content/sections/weather/closings.html).get();
//选择/获取我想要的代码行
元素schoolName=doc.html(“雅典城市学校”);
//一个字符串数组,当我得到它时,我将在其中添加所需的文本
最终ArrayList温度=新ArrayList();
//检查是否正在提取文本
System.out.println(schoolName.text());
//将文本添加到数组中
临时添加(schoolName.text());
对于(int i=0;i
输出:

county: Athens, schoolName: Beacon School, status: Two-hour Delay
county: Franklin, schoolName: City of Grandview Heights, status: Snow Emergency through 8pm Thursday
county: Franklin, schoolName: Electrical Trades Center, status: All Evening Activities Cancelled
county: Franklin, schoolName: Hilock Fellowship Church, status: PM Services Cancelled
county: Franklin, schoolName: International Christian Center, status: All Evening Activities Cancelled
county: Franklin, schoolName: Maranatha Baptist Church, status: PM Services Cancelled
county: Franklin, schoolName: Masters Commission New Covenant Church, status: Bible Study Cancelled
county: Franklin, schoolName: New Life Christian Fellowship, status: All Activities Cancelled
county: Franklin, schoolName: The Epilepsy Foundation of Central Ohio, status: All Evening Activities Cancelled
county: Franklin, schoolName: Washington Ave United Methodist Church, status: All Evening Activities Cancelled
或在循环中:

for (Element tr : doc.select("#closings tr")) {
    System.out.println("----------------------");
    for (Element td : tr.select("td")) {
        System.out.println(td.text());
    }
}
这就产生了:

----------------------
Athens
Beacon School
Two-hour Delay
----------------------
Franklin
City of Grandview Heights
Snow Emergency through 8pm Thursday
----------------------
Franklin
Electrical Trades Center
All Evening Activities Cancelled
...

任何帮助都会有帮助的!这里所有提问的人都希望得到一些帮助来解决他们的问题。没必要大声说出来。我很抱歉,这件事没有引起任何注意,我昨天发了这封信。谢谢你的精彩回答!希望我能表达我的感激之情。既然你把它格式化了,我可以做我需要的事情没错。这就是我正在制作的,它是我节目的快照。
for (Element tr : doc.select("#closings tr")) {
    System.out.println("----------------------");
    for (Element td : tr.select("td")) {
        System.out.println(td.text());
    }
}
----------------------
Athens
Beacon School
Two-hour Delay
----------------------
Franklin
City of Grandview Heights
Snow Emergency through 8pm Thursday
----------------------
Franklin
Electrical Trades Center
All Evening Activities Cancelled
...