<!-- Title --> <td class="title riot" title="Summoners, We will be performing Live Maintenance on the 26/11 at 04:00"> <!-- Title --> <td class="title riot" title="Summoners, We will be performing Live Maintenance on the 26/11 at 04:00"> <!-- Title --> <td class="title riot" title="Summoners, We will be performing Live Maintenance on the 26/11 at 04:00" />

Jsoup के साथ इस पाठ को कैसे पकड़ें?

मैं इस स्रोत कोड से कुछ पाठ निकालने की कोशिश करने के लिए पागल हो रहा हूं:

<tr class="even"> <!-- Title --> <td class="title riot" title="Summoners, We will be performing Live Maintenance on the 26/11 at 04:00 AM, where we will need to bring the EUW Platform offline. Following up...">

I've tried a lot of combinations of constructors, but I can't really do this without any advice... I need to catch the text between the " after title...

Please, note that there's a similar class, called "odd", that has the same syntax of the first one, and this is it:

<tr class="odd">
<!-- Title -->
<td class="title riot" title="Summoners, welcome to the Service Status forum! Here you can come to see information regarding ongoing issues or events that we are currently working...">

So, I need something that can catch the text written on the both classes...

Thanks for the help.

EDIT: Here's my code, where I connect and catch some links:

Document doc = Jsoup.connect("http://forums.euw.leagueoflegends.com/board/forumdisplay.php?f=10")
                                    .userAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.172 Safari/537.22")
                                    .timeout(30000).get();
                    Elements links = doc.select("a[href*=thread]");
                    for (Element link : links){
                        if(link.attr("href").contains("board")||link.attr("href").contains("page")||link.text().matches("1")){}
                        else{
                            titles.add((String) link.text());

                            //descriptions.add((String) DEFAULT_FORUM_URL + link.attr("href"));
                            descriptions.add((String) doc.select("[title*=a]").toString());
                        }
                    }

The commented line writes on each second row of a ListView , the link of the thread, but I need to write there thr brief description that is between those tags "td class="title riot" title=", from each class.

Naturally, this line

descriptions.add((String) doc.select("[title*=a]").toString());

doesn't work.

0

2 उत्तर

इस बारे में कैसा है:

Document doc = Jsoup.connect("http://forums.euw.leagueoflegends.com/board/forumdisplay.php?f=10").get();

for (Element element : doc.select("tr.odd > td, tr.even > td")) {
    System.out.println(element.attr("title"));
}

आउटपुट कौन सा होगा:

Summoners, welcome to the Service Status forum! Here you can come to see information regarding ongoing issues or events that we are currently working...




Summoners, 

We will be performing a maintenance on 26/11 at 04:00 AM, where we will need to bring the EUW Platform offline. 

Following up on the...
0
जोड़ा
मैंने अभी खुद ही ऐसा किया है! खैर, एक तरह का! :) आपका कोड मेरी तुलना में अधिक स्पष्ट है! :) वैसे भी उत्तर के लिए धन्यवाद, मैं अपने संस्करण के साथ अपना कोड बदल दूंगा! :)
जोड़ा लेखक Pipodi, स्रोत
इससे भी बेहतर अगर आप इसे अपने लिए पहले समझते हैं :) वैसे भी मदद करने के लिए खुशी हुई।
जोड़ा लेखक ashatte, स्रोत

यहां एक नमूना है:

public static final String text = "" +
    "<table><tr class=\"even\"> <!-- Title -->\n" +
    "    <td class=\"title riot\"\n" +
    "        title=\"Summoners, We will be performing Live Maintenance on the 26/11 at 04:00 AM, where we will need to bring the EUW Platform offline. Following up...\">\n" +
    "    </td>\n" +
    "</tr>\n" +
    "<tr class=\"odd\">\n" +
    "    <!-- Title -->\n" +
    "    <td class=\"title riot\"\n" +
    "        title=\"Summoners, welcome to the Service Status forum! Here you can come to see information regarding ongoing issues or events that we are currently working...\">\n" +
    "    </td>\n" +
    "</tr></table>";

public static void main(String[] args) throws IOException {
    Document doc = Jsoup.parse(text);

    //System.out.println("your doc:" + doc);

    for (Element element : doc.select("tr > td")) {
        System.out.println(element.attr("title"));
    }
}

प्रिंटों:

Summoners, We will be performing Live Maintenance on the 26/11 at 04:00 AM, where we will need to bring the EUW Platform offline. Following up...
Summoners, welcome to the Service Status forum! Here you can come to see information regarding ongoing issues or events that we are currently working...
0
जोड़ा
उत्तर के लिए धन्यवाद, लेकिन स्रोत पृष्ठ एक वेब पेज है, इसलिए मुझे इसे कनेक्ट करने की आवश्यकता है। इसके अलावा, उस कोड के बाद, एक ही कक्षा में शामिल अन्य कोड है।
जोड़ा लेखक Pipodi, स्रोत