vb如何获取当前IE中打开的网页源代码?

2024-10-31 12:25:22
推荐回答(5个)
回答1:

在窗体内加入控件text1(Multiline=true,scrollbars=2),timer1(interval=1000),
然后在代码区复制下面代码,
运行,即可在text1内实时显示当前IE中打开的网页源代码:

Option Explicit
Dim oShellApp, oShellAppWindows, oWin
Dim UrlLst As String

Private Sub Timer1_Timer()
Set oShellApp = CreateObject("Shell.Application")
Set oShellAppWindows = oShellApp.Windows
For Each oWin In oShellAppWindows
If LCase(TypeName(oWin.document)) = "htmldocument" Then
If InStr(1, UrlLst, oWin.locationurl, vbTextCompare) = 0 Then
UrlLst = UrlLst & oWin.locationurl & ","
Text1.Text = oWin.document.body.innerHTML
Me.Caption = oWin.locationname
End If
End If
Next
End Sub

回答2:

30分我只能告诉你各简单的方法,把网页另存为,再用记事本打开。。。哈哈

回答3:

Dim url

Private Sub Timer1_Timer()
Dim oShellApp, oShellAppWindows, oWin

Set oShellApp = CreateObject("Shell.Application")
Set oShellAppWindows = oShellApp.Windows
For Each oWin In oShellAppWindows
If LCase(TypeName(oWin.Document)) = "htmldocument" Then
If url <> oWin.LocationURL Then
MsgBox oWin.Document.body.innertext
url = oWin.LocationURL
End If
End If
Next
End Sub

回答4:

30分太少。再加130分!

回答5:

右击选查看源代码