クロールされたhtmlファイルからこのpraserを実行しています。このパーサーは、スレッドのタイトル、ユーザーの投稿、および合計ビューを抽出することを想定しています。私はなんとかhtmlタグを取得しましたが、問題はスレッドタイトルのすべてを取得できず、一部しか取得できないことです。
HTMLコード(ウェブサイトのソースコードからコピーしたので、配置が悪くて申し訳ありません):
<tbody id="threadbits_forum_2">
<tr>
<td class="alt1" id="td_threadstatusicon_3396832">
<img src="http://www.hardwarezone.com.sg/img/forums/hwz/statusicon/thread_hot.gif" id="thread_statusicon_3396832" alt="" border="" />
</td>
<td class="alt2"> </td>
<td class="alt1" id="td_threadtitle_3396832" title="Updated on 3 October 2011
Please check Price Guides for latest prices
A PC Buyer’s Guide that is everything to everyone is simply not possible. This is a simple guide to putting together a PC with a local flavour. Be sure to read PC Buyer’s Guide from other media.
If you have any...">
<div>
<span style="float:right">
<img class="inlineimg" src="http://www.hardwarezone.com.sg/img/forums/hwz/misc/sticky.gif" alt="Sticky Thread" />
</span>
<font color=red><b>Sticky: </b></font>
<a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832" id="thread_title_3396832">Buyer's Guide II: Extreme, High-End, Mid-Range, Budget, and Entry Level Systems - Part 2</a>
<span class="smallfont" style="white-space:nowrap">(<img class="inlineimg" src="http://www.hardwarezone.com.sg/img/forums/hwz/misc/multipage.gif" alt="Multi-page thread" border="0" /> <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832">1</a> <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832&page=2">2</a> <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832&page=3">3</a> <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832&page=4">4</a> <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832&page=5">5</a> ... <a href="showthread.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&t=3396832&page=17">Last Page</a>)</span>
</div>
<div class="smallfont">
<span style="cursor:pointer" onclick="window.open('member.php?s=2a7d1dc5bbc6bf85468a79ec2e6eb86e&u=39963', '_self')">adrianlee</span>
</div>
これまでの私のコーディング:
try(BufferedReader br = new BufferedReader(new FileReader(pageThread)))
{
String html = "";
while(br.readLine() != null)
{
html += br.readLine() + "\n";
}
Document doc = Jsoup.parse(html);
//To get the thread list
Elements threadsList = doc.select("tbody[id^=threadbits_forum]").select("tr");
for(Element e: threadsList)
{
//To get the title
System.out.println("Title: " + e.select("a[id^=thread_title]").text());
}
System.exit(0);
}catch(Exception e)
{
e.printStackTrace();
}
結果: タイトル:
- タイトル: HardwareZone 編集チームの一員になりませんか?
- 題名:
- タイトル: pa9797 is back to PC wa new Rig!!
- タイトル: [EPIC] Andyson のもう 1 つの初、Platinum Modular PSU
- 題名:
- タイトル: 新しい CPU を購入するのに適した SLS のショップは? . . . すぐ
この問題の回避策はありますか?
ありがとう。