【问题标题】:HTMLagility pack - reading xml pageHTMLagility 包 - 读取 xml 页面
【发布时间】:2014-02-20 10:43:40
【问题描述】:

您好,我在网上有一个 xml 文件,我想抓取它以获取相关信息

<M MId="1195772" LId="34923" _LId="34921" OId="569" SId="5" KId="122" LNr="2" C0="1392715800" ML="1" HId="13106" GId="5996" W="" HN="Musfat Banyas" GN="Omyyah Idlib" HRC="" HRCi="1" GRC="" GRCi="0" Info="" S1="1-1" S2="1-0" MStan="1" OTv="" L="0" A="3" Ao="11"/>

我想把每一个M刮下来,得到HN GN S1 S2的值

我已经尝试使用下面的代码,但我没有得到任何返回值

Imports System.Net
Imports System.IO
Imports System.Xml
Imports HtmlAgilityPack


Partial Class Grayhounds_home
    Inherits System.Web.UI.Page
    '  Gettodaysmatches(cominguptable, "https://www.betfair.com/sport/football?selectedTabType=TODAY", ".//div[contains(@class, 'match event-information ui-event')]", ".//span[@class='home-team-name']", ".//span[@class='away-team-name']", ".//span[@class='ui-no-score']")

    Private Sub Grayhounds_home_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim webGet As New HtmlWeb() 'open the system
        Dim htmlDoc As HtmlDocument = webGet.Load("http://www.futbol24.com/matchDayXml/?Day=20140218") '' get the html from the webpage
        Dim coll As HtmlNodeCollection = htmlDoc.DocumentNode.SelectNodes("//m")
        If coll IsNot Nothing Then
            For Each div As Object In coll ' select all the divs wi
            test.Text = div.Attributes("HN").Value
            Next
        End If
    End Sub
End Class

【问题讨论】:

    标签: asp.net .net xml vb.net html-agility-pack


    【解决方案1】:

    通过使用 .NET 内置类:XDocumentXmlDocument,您有更好的解析 XML 文件的选项。例如,使用XmlDocument

    Dim doc As New XmlDocument
    doc.Load("http://www.futbol24.com/matchDayXml/?Day=20140218")
    Dim coll = doc.SelectNodes("//M")
    For Each M As XmlNode In coll
        test.Text = M.Attributes("HN").Value
    Next
    

    【讨论】:

    • 太棒了,甚至不知道它的存在!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    相关资源
    最近更新 更多