在最近的一个问题中,vbscript 使用 InStr 查找在 URL 中变化的信息,我曾询问过如何在 URL 中查找信息。后来我意识到我不需要在 URL 中查找信息,我只需要能够从 Internet Explorer 的位置框中捕获 URL,并能够使用它从网页中收集数据。这是我到目前为止所拥有的:
Option Explicit
Dim objIE, objShell, objShellWindows
Dim strIDNum, strURL, strWindow, strURLFound, WShell, i
'=============================================================
'=== Code for capturing URL of current page will go here ===
'=============================================================
strURL = 'URL that is captured by the above coding
strWindow = "Workflow Process"
Set objIE = CreateObject("InternetExplorer.Application")
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
Set WShell = CreateObject("WScript.Shell")
strURLFound = False
'To fix item not found error
For Each objIE in objShellWindows
Next
For i = 0 to objShellWindows.Count - 1
Set objIE = objShellWindows.Item(i)
On Error Resume Next
If InStr(Ucase(objShellWindows.Item(i).LocationURL), Ucase(strURL)) Then
If InStr(Ucase(objShellWindows.Item(i).FullName), "IEXPLORE.EXE") Then
If Err.Number = 0 Then
If InStr(objShellWindows.Item(i).document.title, (strWindow)) Then
strURLFound = True
Exit For
End If
End If
End If
End If
Next
一旦我有了我的用户将访问的网站的 URL,我将使用下面的代码来收集信息:
WShell.AppActivate strWindow
WScript.Sleep 300
strIDNum = objIE.document.getElementByID("ID_PlaceHolder").value
如何从他们所在的页面获取 URL?