如何解析经典asp中的reddit RSS提要?

时间:2019-05-30 22:02:45

标签: xml asp-classic

我希望多年来已经回答了这个问题,但是一直没有。我正在尝试使用经典ASP解析Reddit RSS feed,但是无法通过线程解析。我可以加载它,但是到目前为止,对我来说,解析它是不可能的。

我正在尝试解析任何RSS提要,例如https://www.reddit.com/r/worldnews.rss

我正在使用以下脚本:

rss_url ="https://www.reddit.com/r/worldnews.rss"
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    Err.Clear ' shouldn't be needed; can't hurt
    'ON ERROR RESUME NEXT
xml.open "GET", rss_url, False
xml.send
    'ON ERROR GOTO 0
    If Err.Number <> 0 Then
        Response.Write "NO feed from ..."
    Else
 ResponseXML = xml.responseText
 'response.write "<hr>"&ResponseXML&"<hr>"
Set doc = Server.CreateObject("Microsoft.DOMDocument")
doc.loadXML( xml.ResponseXML.xml )

Set items = doc.getElementsByTagName("entry")

For inum = 0 To items.length-1 
    Set curitem = items.entry(inum)
    title = Replace( curitem.SelectSingleNode("title").text, "'", "''" )
    content = Replace( curitem.SelectSingleNode("content").text, "'", "''" )
    Set linkNode = curitem.SelectSingleNode("link") 
    If linkNode Is Nothing Then 
        link = "**NONE**" ' if no description given, supply this 
    Else 
        link = Replace( linkNode.text, "'", "''" ) 
    End If 
    'link =  Replace( curitem.SelectSingleNode("link").text, "'", "''" ) 
    Set descNode = curitem.SelectSingleNode("description") 
    If descNode Is Nothing Then 
        description = "**NONE**" ' if no description given, supply this 
    Else 
        description = Replace( descNode.text, "'", "''" ) 
    End If
         response.write "<strong>"& title & "</strong><br>"& description &"<br>"& content &"<br>"& link &"<hr><br><br>"
Next

提要已加载,但我认为它没有加载到dom中。我不知道怎么了。

1 个答案:

答案 0 :(得分:1)

rss_url ="https://www.reddit.com/r/worldnews.rss"
Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    Err.Clear ' shouldn't be needed; can't hurt
    'ON ERROR RESUME NEXT
    xml.open "GET", rss_url, False
    xml.send
    'ON ERROR GOTO 0
    If Err.Number <> 0 Then
        Response.Write "NO feed from ..."
    Else
 ResponseXML = xml.responseText
 'response.write "<hr>"&ResponseXML&"<hr>"
 'response.end

Set doc = CreateObject("MSXML2.DOMDocument")
doc.loadXML( ResponseXML )

Set items = doc.getElementsByTagName("entry")

    For inum = 0 To items.length-1 
        Set curitem = items(inum)
        title = Replace( curitem.SelectSingleNode("title").text, "'", "''" )
        content = Replace( curitem.SelectSingleNode("content").text, "'", "''" )
        Set linkNode = curitem.SelectSingleNode("link") 
        If linkNode Is Nothing Then 
            link = "**NONE**" ' if no description given, supply this 
        Else 
            link = Replace( linkNode.text, "'", "''" ) 
        End If 
        'link =  Replace( curitem.SelectSingleNode("link").text, "'", "''" ) 
        Set descNode = curitem.SelectSingleNode("description") 
        If descNode Is Nothing Then 
            description = "**NONE**" ' if no description given, supply this 
        Else 
            description = Replace( descNode.text, "'", "''" ) 
        End If
             response.write "<strong>"& title & "</strong><br>"& description &"<br>"& content &"<br>"& link &"<hr><br><br>"
    Next
end if