以下是网页的HTML,我愿意提取所有数据用户ID字段的值
<div class="account js-actionable-user js-profile-popup-actionable " data-screen-name="ducttape" data-user-id="817977">
<div class="account js-actionable-user js-profile-popup-actionable " data-screen-name="adage" data-user-id="12480582">
任何人都可以提供帮助是c#或vb.net我试过跟随代码,但它不起作用
Dim UrlRegister1 As String = "C:/Users/Shripad/Desktop/result.htm"
Dim document = New HtmlDocument()
document.Load("C:/Users/Shripad/Desktop/result.htm")
Dim node As HtmlNode = document.DocumentNode.SelectSingleNode("//class='account js-actionable-user js-profile-popup-actionable'/data-user-id=")
Dim useridd As String = node.Attributes("Value").Value
答案 0 :(得分:0)
为了选择具有'account'类的元素 - 使用XPath包含这样的选择器:
[contains(@class, 'account')]
整个结果应该是:
var node = doc.DocumentNode.SelectSingleNode(@"//div[contains(@class, 'account')]");
var useridd = node.Attributes["data-user-id"].Value;
以下是有关按类选择元素的更多信息:XPath for CSS classes