简体   繁体   中英

Parsing table elements with Jsoup

I'm trying to parse data from this table . Let's say, for example, that I want to parse the second elements from the second row (called SLO).

在此处输入图片说明

I can see there is a TR inside TR and the SLO word doesn't even have an ID or anything. How can I parse this?

This is the code:

class Title extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        tw1.setText("Loading...");
    }

    @Override
    protected Void doInBackground(Void... params) {
            try {
                Document doc = Jsoup.connect("https://www.easistent.com/urniki/cc45c5d0d303f954588402a186f5cdba5edb51d6/razredi/16515").get();
                Elements eles = doc.select("");
                title = eles.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        tw1.setText(title);
    }

}

I don't know what to put in the doc.select(""); because I've never parsed something like this. I've only parsed titles of webpages and such. Could someone help me with this?

There is plenty of information there for you to use, for example class names or title attributes. The URL you provided won't work for me, and I can't copy paste the HTML from your image so my example will show just the parsing of the span based on its title:

String html = "<span title='Slovenscina'>SLO</span>";
Document doc = Jsoup.parse(html);
Elements eles = doc.select("span[title=Slovenscina]");
String title = eles.text();
System.out.println(title);

Will output:

SLO

This will work in the scope of the other HTML that you provided. I suggest you read some more about the selector-syntax of Jsoup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM