0
我习惯于VBA,但是我从未尝试过VB .NET,我需要将2个网页中的文本转换为文本文件。这是我正在使用的代码,但我有问题!我必须做些什么才能使其发挥作用?将网页内容写入文本文件
Public mIE As Object
Public arrText(1) As String
Public Const myFile As String = "C:\myTextFile.txt"
Public Sub Main()
Dim arrURL(1) As String
Dim i As Byte
On Error Resume Next
Kill (myFile)
' Define URL
arrURL(0) = "http://URL1"
arrURL(1) = "http://URL2"
For i = 0 To 1
'Spawn Internet Explorer
mIE = CreateObject("InternetExplorer.Application")
arrText(i) = openWebPage(arrURL(i))
mIE.Quit()
mIE.Close()
mIE = Nothing
Next
Call saveToTextFile
End Sub
Public Function openWebPage(myURL As String) As String
With mIE
.Top = 0
.Left = 0
.Height = 800
.Height = 600
.AddressBar = 0
.StatusBar = 0
.Toolbar = 0
.Visible = True
.navigate (myURL)
End With
openWebPage = mIE.document.body.innerText
End Function
Public Sub saveToTextFile()
Dim oWriter As New System.IO.StreamWriter(myFile)
Dim i As Byte
For i = 0 To UBound(arrText)
oWriter.WriteLine (arrText(i))
Next
oWriter.Close()
End Sub
问候, 埃利奥·费尔南德斯
你有什么问题? –
我有的问题是在主程序的for循环中。当i = 1时,arrText(i)= openWebPage(arrURL(i))返回'Nothing'。它应该返回第二个URL页面的内容。 –