2

我需要使用站点http://www.informatik.uni-trier.de/~ley/pers/hd/k/Kumar:G=_Praveen.html中的 jsoup 库来解析 HTML 中的两个表 。因为有页面上有两个表格,我不知道如何解析表格内容。我需要提取第一个表格的内容,即只有作者姓名及其出版物和最后命名为共同作者的第二个表格......我试图编码(下面给出的代码)但它给出了错误......</p>

public class Main {
    public static void main(String[] args) {
        try {
            Document doc =Jsoup.connect(“http://www.informatik.unitrier.de/~ley/pers/hd/k/Kumar:G=_Praveen.html“).get();
            Elements trs = doc.select(“table tr”);
            Element table = doc.select(“table[class=coauthor]“).first();
            Iterator ite = table.select(“td”).iterator();
            ite.next();
            System.out.println(“Value 1: ” + ite.next().text());
            System.out.println(“Value 2: ” + ite.next().text());
            System.out.println(“Value 3: ” + ite.next().text());
            System.out.println(“Value 4: ” + ite.next().text());
            trs.remove(0);
            for (Element tr : trs) {
                Elements tds = tr.getElementsByTag(“td”);
                Element td = tds.first();
                System.out.println(“Blog: ” + td.text());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

请建议我在上面的代码中需要做哪些确切的更改,以便我从表中获得我需要的确切信息..任何帮助将不胜感激..thanx 提前..

4

1 回答 1

2

作者和der出版物:

final String url = "http://www.informatik.uni-trier.de/~ley/pers/hd/k/Kumar:G=_Praveen.html";
Document doc = Jsoup.connect(url).get();


for( Element element : doc.select("table div.data") )
{
    // System.out.println(element); // Use this line if you need the HTML Element instead of the text
    System.out.println(element.text());
}

输出:

G. Praveen Kumar, Anirban Sarkar: Weighted Association Rule Mining and Clustering in Non-binary Search Space. ITNG 2010: 238-243
G. Praveen Kumar, Arjun Kumar Murmu, Biswas Parajuli, Prasenjit Choudhury: MULET: A Multilanguage Encryption Technique. ITNG 2010: 779-782
G. Praveen Kumar, Anirban Sarkar, Narayan C. Debnath: A New Algorithm for Frequent Itemset Generation in Non-Binary Search Space. ITNG 2009: 149-153

合著者:

for( Element element : doc.select("table td.coauthor") )
{
    System.out.println(element.text());
}

输出:

Prasenjit Choudhury
Narayan C. Debnath
Arjun Kumar Murmu
Biswas Parajuli
Anirban Sarkar
于 2013-01-04T19:10:17.877 回答