【问题标题】:How to parse a reddit rss feed in classic asp?如何在经典 asp 中解析 reddit RSS 提要?
【发布时间】:2019-05-30 22:02:45
【问题描述】:

多年来,我一直希望这个问题得到解答,但事实并非如此。我正在尝试使用经典 ASP 解析 Reddit RSS 提要,但我无法通过线程解析。我可以加载它,但到目前为止对我来说解析它是不可能的。

我正在尝试解析任何 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 中。我不确定出了什么问题。

【问题讨论】:

    标签: xml asp-classic


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多