您好,我想弄清楚如何使用 VBS 解析 RSS 提要并将内容显示到 cmd 中。我得到了一些我在网上找到的代码。这就是我到目前为止所得到的。
批处理文件:
:news
start scripts\xml\getxml.exe -N --directory-prefix=%temp% http://feeds.bbci.co.uk/news/rss.xml
:newscheck
if NOT EXIST %temp%\rss.xml (
ping 123.45.67.89 -n 1 -w 500 > nul.
goto newscheck
)
start scripts\news\parsebbcnews.vbs
ping 123.45.67.89 -n 1 -w 500 > nul.
:newsxmlparsecheck
if NOT EXIST %temp%\bbcnews.txt (
ping 123.45.67.89 -n 1 -w 500 > nul.
goto newsxmlparsecheck
)
set /p headline= <%temp%\bbcnews.txt
echo %headline%
%speech% "%headline%"
del %temp%\rss.xml
del %temp%\bbcnews.txt
goto start
然后这将启动 VBS:
Dim xmlDoc, objNodeList, plot
Set wshShell = CreateObject( "WScript.Shell" )
tfolder = wshShell.ExpandEnvironmentStrings("%TEMP%")
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load(tfolder & "\rss.xml")
Set objNodeList = xmlDoc.getElementsByTagName("channel/item/description") 'Node to search for
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Write all found results into forecast.txt
Const ForWriting = 2
Set objTextFile = objFSO.OpenTextFile _
(tfolder & "\bbcnews.txt", ForWriting, True)
If objNodeList.length > 0 then
For each x in objNodeList
plot=x.Text
objTextFile.WriteLine(plot)
Next 'just remove this?
objTextFile.Close
End If
'Extract todays data (first line) from 'forecast.txt' and write each data type to seperate line in today.txt
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
(tfolder & "\bbcnews.txt", ForReading)
strNextLine = objTextFile.Readline
'currentsplit = Split(strNextLine , ", ")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(tfolder & "\headline.txt", ForWriting, True)
objTextFile.WriteLine(strNextLine)
这从 bbc 获得 1 个新闻 rss 提要。我还希望显示多个提要。
我没有创建此代码,所以我不知道如何获取脚本和类似代码以从不同站点获取 rss。所以基本上我想知道如何使用 vb-script 执行此操作并将其显示在 cmd 中。