如何在Jsoup android中解析并显示表

时间:2022-10-31 07:32:20

i have some problems with jsoup.

我有jsoup的一些问题。

this is the link i want to parse: http://roosters.gepro-osi.nl/roosters/rooster.php?klassen%5B%5D=L2vp&type=Klasrooster&wijzigingen=1&school=905/ . I want to select te table content and display it nice and clean in my app. this is the script i already have:

这是我要解析的链接:http://roosters.gepro-osi.nl/roosters/rooster.php?klassen%5B%5D = L2vp&type = Klasrooster&wijzigingen = 1&school = 905 /。我想选择te table内容并在我的应用程序中显示它很干净。这是我已经拥有的脚本:

    package rsg.deborgen.nl;



     import org.jsoup.Jsoup;
     import org.jsoup.nodes.Document;
     import org.jsoup.select.Elements;

     import android.app.Activity;
     import android.os.Bundle;
     import android.view.View;
     import android.widget.Button;
     import android.widget.TextView;

     public class Lindenborg1Activity extends Activity {
Button btn_2p;




// blog url
static final String BLOG_URL = "http://roosters.gepro-osi.nl/roosters/rooster.php?klassen%5B%5D=L2vp&type=Klasrooster&wijzigingen=1&school=905/";


@Override
public void onCreate(Bundle savedInstanceState) {
    // set layout view
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btn_2p =(Button) findViewById(R.id.button1);

    btn_2p.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            // process


                // set layout view
                setContentView(R.layout.rooster);

            try {
                ((TextView)findViewById(R.id.tv)).setText(getBlogStats());
            } catch (Exception ex) {
                ((TextView)findViewById(R.id.tv)).setText("Error");
            }
        }

        protected String getBlogStats() throws Exception {
            String result = "";
            // get html document structure
            Document document = Jsoup.connect(BLOG_URL).get();
            // selector query
            Elements nodeBlogStats = document.select("td.tableheader");
            // check results
            if(nodeBlogStats.size() > 0) {
                // get value
                result = nodeBlogStats.get(0).text();
            }

            // return
            return result;

(i leaved away the end because of it was going wrong with code block)

(由于代码块出错,我最后离开了)

but if i run it now it shows me the whole site and i want only the text in the table. so please help me, thanks!

但如果我现在运行它它会向我显示整个网站,我只想要表格中的文字。所以请帮助我,谢谢!

(Ps. this script is from another tut but i can't remeber its name and sorry for my nooblism and bad english :D )

(Ps。这个剧本来自另一个啧啧但是我不能记住它的名字,对不起我的nooblism和坏英语:D)

1 个解决方案

#1


0  

try document.select("tr.AccentDark td.tableheader")

尝试document.select(“tr.AccentDark td.tableheader”)

#1


0  

try document.select("tr.AccentDark td.tableheader")

尝试document.select(“tr.AccentDark td.tableheader”)