因此,我试图在论坛上获取在线用户列表。这是 html 的样子:
<!-- logged-in users -->
<div id="wgo_onlineusers" class="wgo_subblock section">
<h3 class="blocksubhead"><img src="images/metro/red/misc/users_online.png" alt="Currently Active Users" />Currently Active Users</h3>
<div>
<p>There are currently <a href="online.php">3 users online</a>. <span class="shade">3 members and 0 guests</span></p>
<p>Most users ever online was 23, 01-06-2013 at <span class="time">12:09 PM</span>.</p>
<ol class="commalist" id="wgo_onlineusers_list">
<li><a class="username" href="http://website.com/member.php?u=13"><span class="vip_username">Duncanrp</span></a>, </li>
<li><a class="username" href="http://website.com/member.php?u=17"><span class="regular_username">Jessica</span></a></li>
</ol>
</div>
</div>
<!-- end logged-in users -->
是否可以使用 HtmlAgilityPack 获取在线的每个单独用户?使用<li>
标签对用户进行格式化。
我尝试过的代码:
HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
htmlDocument.LoadHtml("http://www.vizor.us/forum.php");
List<string> onlineUsers = new List<string>();
foreach (HtmlAgilityPack.HtmlNode selectNode in htmlDocument.DocumentNode.SelectNodes("//li/a[@class='username']"))
{
onlineUsers.Add(selectNode.InnerText);
}
谢谢。