Я схожу с ума, просто пытаясь извлечь какой-то текст из этого исходного кода:
<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...">
Я пробовал много комбинаций конструкторов, но я не могу сделать это без каких-либо советов... Мне нужно поймать текст между "после заголовка"...
Пожалуйста, обратите внимание, что существует аналогичный класс, называемый "нечетным", который имеет тот же синтаксис первого, и это он:
<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...">
Итак, мне нужно что-то, что может поймать текст, написанный на обоих классах...
Спасибо за помощь.
EDIT: Здесь мой код, где я соединяю и улавливаю некоторые ссылки:
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());
}
}
Прокомментированная строка записывает каждую вторую строку ListView, ссылку на поток, но мне нужно написать краткое описание, которое находится между этими тегами "td class=" title riot "title=" из каждого класса.
Естественно, эта линия
descriptions.add((String) doc.select("[title*=a]").toString());
не работает.
Как насчет этого:
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...
Вот пример:
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...