嗨我在网上有一个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
答案 0 :(得分:0)
通过使用.NET内置类:XDocument或XmlDocument,您可以更好地解析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