일반적으로 인터넷 익스플로러를 사용합니다. 이것에 대한 연구의 COM 개체 : 그러나
root = "C:\base\dir"
Set ie = CreateObject("InternetExplorer.Application")
For Each f In fso.GetFolder(root).Files
ie.Navigate "file:///" & f.Path
While ie.Busy : WScript.Sleep 100 : Wend
text = ie.document.getElementById("MySection").innerText
WScript.Echo Replace(text, vbNewLine, "")
Next
는 <section>
태그는 getElementById("MySection")
는 여는 태그를 반환으로 COM 객체가 제대로 처리하지 않는 것 이전에 IE 9, 심지어 IE 9에서 지원되지 않습니다 :
>>> wsh.echo ie.document.getelementbyid("MySection").outerhtml
<SECTION id=MySection>
당신은하지만, 대신에 정규 표현식을 사용할 수
root = "C:\base\dir"
Set fso = CreateObject("Scripting.FileSystemObject")
Set re1 = New RegExp
re1.Pattern = "<section id=""MySection"">([\s\S]*?)</section>"
re1.Global = False
re2.IgnoreCase = True
Set re2 = New RegExp
re2.Pattern = "(<br>|\s)+"
re2.Global = True
re2.IgnoreCase = True
For Each f In fso.GetFolder(root).Files
html = fso.OpenTextFile(filename).ReadAll
Set m = re1.Execute(html)
If m.Count > 0 Then
text = Trim(re2.Replace(m.SubMatches(0).Value, " "))
End If
WScript.Echo text
Next
+1을 적절한 파서와 전체 우아한 솔루션을 사용하여 제안합니다. –