如何刮取并保存到文本文件inVBScript

如何刮取并保存到文本文件inVBScript,vbscript,getelementbyid,getelementsbytagname,getelementsbyclassname,Vbscript,Getelementbyid,Getelementsbytagname,Getelementsbyclassname,我是新来的。从web上的示例编写VBScript代码。我正在尝试从网页中获取和文本,并将其保存到文本文件中。下面是一个网页数据示例,后面是我的一些失败代码。在PC上运行Windows 7 home premium “这是我正在访问的网页=========== <body> <div class stuff <div id stuff <div class="header-info"> <h1>The Girl I Love</h1&

我是新来的。从web上的示例编写VBScript代码。我正在尝试从网页中获取和文本,并将其保存到文本文件中。下面是一个网页数据示例,后面是我的一些失败代码。在PC上运行Windows 7 home premium

“这是我正在访问的网页===========

<body>
<div class stuff
<div id stuff

<div class="header-info">
    <h1>The Girl I Love</h1>
    <h2>Tony Bennet</h2>

<more div stuff
'=== attach to an already running IE instance:
Set app = CreateObject("Shell.Application")
For Each window In app.Windows()
  If InStr(1, window.FullName, "iexplore", vbTextCompare) > 0 Then
    Set ie = window
    Exit For
  End If
Next

'Set up text file to write to
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\users\kp\desktop\output.txt", 2, True, -1)

'Various Code line tests - and results
f.Write ie.document.body 'returns [object HTMLBodyElement]
f.Write ie.document.body.innerText 'returns all body text
f.Write ie.document.getElementsByClassName("header-info")   'returns [object HTMLCollection]
f.Write ie.document.getElementsByTagName("<h1>") 'returns [object HTMLCollection]
f.Write ie.document.getElementsByTagName("<h1>").innerText 'FAILS not valid

kpmsg = "you're done"
Wscript.echo kpmsg
“这是我的密码==============================

<body>
<div class stuff
<div id stuff

<div class="header-info">
    <h1>The Girl I Love</h1>
    <h2>Tony Bennet</h2>

<more div stuff
'=== attach to an already running IE instance:
Set app = CreateObject("Shell.Application")
For Each window In app.Windows()
  If InStr(1, window.FullName, "iexplore", vbTextCompare) > 0 Then
    Set ie = window
    Exit For
  End If
Next

'Set up text file to write to
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\users\kp\desktop\output.txt", 2, True, -1)

'Various Code line tests - and results
f.Write ie.document.body 'returns [object HTMLBodyElement]
f.Write ie.document.body.innerText 'returns all body text
f.Write ie.document.getElementsByClassName("header-info")   'returns [object HTMLCollection]
f.Write ie.document.getElementsByTagName("<h1>") 'returns [object HTMLCollection]
f.Write ie.document.getElementsByTagName("<h1>").innerText 'FAILS not valid

kpmsg = "you're done"
Wscript.echo kpmsg
完整的程序在这里

过滤器仅读取和写入标准输入和标准输出。这些选项仅在命令提示符下可用

filter <inputfile >outputfile
filter <inputfile | other_command
other_command | filter >outputfile
other_command | filter | other_command
从web检索文件并将其写入标准输出

webaddress - a web address fully specified including http://
范例

获取Microsoft的主页

filter web http://www.microsoft.com
标签

从文本中删除HTML标记

范例

为集合中的每件事物读取集合:语句:下一步

filter web http://www.microsoft.com
filter tags
filter web http://www.microsoft.com | filter tags