我正在抓取的 HTML 如下。它包含一个帖子和 2 个回复:
<div class="share_buttons noprint">...</div>
<strong>Dan</strong> Says:<br/>
<span class="small soft"><time datetime="2009-10-05T02:27:38Z">Sun, Oct 04 '09, 7:27 PM</time></span>
<div class="quote_top"> </div>
<div class="quote_item">Hello all, this is my original post.<br/></div>
<form class="action_heading noprint">
<strong>Page</strong>
...
</form>
<div class="post_number" id="r_140626">1</div>
<strong>AnnieMae</strong> Says:<br/>
<span class="small soft"><time datetime="2009-10-05T02:30:27Z">Sun, Oct 04 '09, 7:30 PM</time></span>
<div class="quote_top clear_float"> </div>
<div class="quote_item">What do you think of it?<br/></div>
<div class="post_number" id="r_140627">2</div>
<strong>Thomas77</strong> Says:<br/>
<span class="small soft"><time datetime="2009-10-05T02:32:32Z">Sun, Oct 04 '09, 7:32 PM</time></span>
<div class="quote_top clear_float"> </div>
<div class="quote_item">Not really sure, can't see this pic?<br/>
</div>
所以我已经想出了如何获得原始帖子......
'get AUTHOR and DATE of original post
Dim divOriginalPostAuthor As HtmlNode = threadDoc.DocumentNode.SelectSingleNode("//div[@class='share_buttons noprint']/following-sibling::strong")
Dim divOriginalPostDate As HtmlNode = threadDoc.DocumentNode.SelectSingleNode("//div[@class='share_buttons noprint']/following-sibling::span/time")
Dim strDate As String = divOriginalPostDate.InnerText.Trim
strDate = strDate.Remove(0, InStr(strDate, ", ")).Trim
strDate = Replace(strDate, "'", 20)
Dim strAuthor As String = (divOriginalPostAuthor.InnerText).Trim
dtPosted = CDate(strDate)
divOriginalPostText = threadDoc.DocumentNode.SelectSingleNode("//div[@class='share_buttons noprint']/following-sibling::div[@class='quote_item']")
现在我只是想弄清楚如何获得回复......我正在考虑像这样获得当前行位置:
Dim currentNodePosition As Integer = threadDoc.DocumentNode.SelectSingleNode("//form[@class='action_heading noprint']").Line
然后在我增加当前行位置时使用它来遍历回复。对我来说这很棘手的想法是回复没有“容器”html元素供我立即收集....有什么想法吗?