2013-07-24 37 views
0

我在嘗試URL的XML,但它似乎無法工作。它只適用於我從本地文件讀入它的情況。不能讀取XML遍歷的URL,只能在本地讀取

我想要閱讀的網頁是:http://na.lolesports.com/api/standings?tournament=7

非常感謝你的幫助

Set xmlObject = CreateObject("Microsoft.XMLDOM") 
'urlPath = "na.lolesports.com/api/standings?tournament=7/standings.xml" 
'urlPath = "na.lolesports.com/api/standings?tournament=7" 
'urlPath = "C:\Trio Scripts\standings.xml" 
xmlObject.load(urlPath) 

if (not isNull(xmlObject)) then 

set nodes = xmlObject.selectNodes("//team_title") 
for i = 0 to (nodes.length - 1) 
    msgbox(nodes(i).nodeName & " - " & nodes(i).text) 
next 
end if 

回答

1

這個片斷:

Dim sUrl  : sUrl   = "http://na.lolesports.com/api/standings?tournament=7" 
' Dim sUrl  : sUrl   = "na.lolesports.com/api/standings?tournament=7" 
    Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument.6.0") 
    objMSXML.async = False 
    objMSXML.load sUrl 

    If 0 = objMSXML.parseError Then 
    WScript.Echo "ok" 
    Else 
    WScript.Echo objMSXML.parseError.reason 
    End If 

可以用來證明前綴「http://」是Url的一部分並且是必需的。

(有用於原因所有你和我的代碼之間的其他差異。)

+0

tytytyty會馬上對其進行測試,BRB在一個位 – user1189352

+0

它的工作!!!!!!!如果可能的話,僅僅出於知識的原因,你能解釋一下你是如何或爲什麼這樣做的? – user1189352

+0

哦,忘了提及,我沒有把我的代碼中的「http://」部分之前,並沒有工作..但你的代碼呢! – user1189352