Any one have a good way to scrape RSS feeds for information? As time goes on I find that more sites have an RSS feed that has the information I am looking for, everything from IP addresses to weather info. Currently my scripts parse through the feed based on line numbers, problem with that is they break anytime the feed changes format.
Anyone found a good reliable way to use MS to parse the info in RSS feeds?
Thanks
-Joe
Easy way to parse RSS feeds?
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You can use the MSXML2 object in VBScript. The following is quick and dirty but it grabs the RSS feed from my blog and then outputs each entry (it gets the title, link and content).
VBSTART
Dim TitlesArray()
Dim LinksArray()
Dim ContentArray()
Dim ItemNum
Dim nodetype
sub traverse(xmlTree)
dim nodes, i, n
if xmlTree.hasChildNodes then
if xmlTree.nodename = "item" then
ItemNum = ItemNum + 1
Redim preserve TitlesArray(ItemNum)
Redim preserve LinksArray(ItemNum)
Redim preserve ContentArray(ItemNum)
end if
if ItemNum > 1 then
nodetype = xmlTree.nodename
end if
nodes = xmlTree.childNodes.length
for i = 0 to nodes - 1
set n = xmlTree.childNodes(i)
traverse n
next
else
'MsgBox xmlTree.text
if nodetype = "title" then
TitlesArray(ItemNum-1) = xmlTree.text
end if
if nodetype = "link" then
LinksArray(ItemNum-1) = xmlTree.text
end if
if nodetype = "content:encoded" then
ContentArray(ItemNum-1) = xmlTree.text
end if
end if
set n = nothing
end sub
Sub DoRSS(xmlFile)
dim objXML, nodeList, node, root
set objXML = CreateObject("MSXML2.DOMDocument.4.0")
ItemNum = 1
objXML.async = false
objXML.load(xmlFile)
set root = objXML.documentElement
traverse root
set root = nothing
set nodelist = nothing
set objXML = nothing
End sub
VBEND
HTTPRequest>http://www.mjtnet.com/blog/?feed=rss2,% ... xml,GET,,r
VBRun>DoRSS,%SCRIPT_DIR%\rss.xml
VBEval>ItemNum,maxItems
Let>maxItems=maxItems-1
Let>k=1
Repeat>k
VBEval>TitlesArray(%k%),title
VBEval>LinksArray(%k%),link
VBEval>ContentArray(%k%),content
MessageModal> %title% %CRLF% link:%link% %CRLF% %CRLF% %content%
Let>k=k+1
Until>k=maxItems
VBSTART
Dim TitlesArray()
Dim LinksArray()
Dim ContentArray()
Dim ItemNum
Dim nodetype
sub traverse(xmlTree)
dim nodes, i, n
if xmlTree.hasChildNodes then
if xmlTree.nodename = "item" then
ItemNum = ItemNum + 1
Redim preserve TitlesArray(ItemNum)
Redim preserve LinksArray(ItemNum)
Redim preserve ContentArray(ItemNum)
end if
if ItemNum > 1 then
nodetype = xmlTree.nodename
end if
nodes = xmlTree.childNodes.length
for i = 0 to nodes - 1
set n = xmlTree.childNodes(i)
traverse n
next
else
'MsgBox xmlTree.text
if nodetype = "title" then
TitlesArray(ItemNum-1) = xmlTree.text
end if
if nodetype = "link" then
LinksArray(ItemNum-1) = xmlTree.text
end if
if nodetype = "content:encoded" then
ContentArray(ItemNum-1) = xmlTree.text
end if
end if
set n = nothing
end sub
Sub DoRSS(xmlFile)
dim objXML, nodeList, node, root
set objXML = CreateObject("MSXML2.DOMDocument.4.0")
ItemNum = 1
objXML.async = false
objXML.load(xmlFile)
set root = objXML.documentElement
traverse root
set root = nothing
set nodelist = nothing
set objXML = nothing
End sub
VBEND
HTTPRequest>http://www.mjtnet.com/blog/?feed=rss2,% ... xml,GET,,r
VBRun>DoRSS,%SCRIPT_DIR%\rss.xml
VBEval>ItemNum,maxItems
Let>maxItems=maxItems-1
Let>k=1
Repeat>k
VBEval>TitlesArray(%k%),title
VBEval>LinksArray(%k%),link
VBEval>ContentArray(%k%),content
MessageModal> %title% %CRLF% link:%link% %CRLF% %CRLF% %content%
Let>k=k+1
Until>k=maxItems
Last edited by Marcus Tettmar on Fri Mar 03, 2006 5:23 pm, edited 1 time in total.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
-
- Pro Scripter
- Posts: 149
- Joined: Tue Mar 23, 2004 9:11 pm
Hi!
Is it possile to also extract the values after the attr?
So that the result from 6 would be something like :00400253 SH 2 6
Thanks for any input!
Is it possile to also extract the values after the attr?
So that the result from 6 would be something like :00400253 SH 2 6
Thanks for any input!
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<com>
<attr tag="00400253" vr="SH" len="2">6</attr>
<attr tag="00400254" vr="LO" len="0"/>
<attr tag="00400255" vr="LO" len="0"/>
<attr tag="00400260" vr="SQ" len="-1">
<item>
<attr tag="00080100" vr="SH" len="8">SIN</attr>
<attr tag="00080102" vr="SH" len="12">Unique</attr>
</item>
</attr>
<attr tag="00400270" vr="SQ" len="-1">
<item>
<attr tag="00080050" vr="SH" len="14">8901</attr>
<attr tag="00081110" vr="SQ" len="0"/>
<attr tag="0020000D" vr="UI" len="60">20090713142540.23038248901</attr>
<attr tag="00321060" vr="LO" len="0"/>
<attr tag="00400007" vr="LO" len="0"/>
<attr tag="00400008" vr="SQ" len="0"/>
<attr tag="00400009" vr="SH" len="14">901</attr>
<attr tag="00401001" vr="SH" len="14">901</attr>
</item>
</attr>
</com>