0

在最近的一个问题中,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?

4

2 回答 2

1

你试过objIE.LocationURL吗?另外,感谢 Tomalak 提供objIE.document.location.href.

于 2013-12-09T14:22:30.187 回答
0

我能够弄清楚如何从另一个 URL 发生变化的网站获取信息。首先,我需要基本 URL 至少可以让我到达那里,一旦找到,URL 中的附加信息实际上并不重要,因为每个页面都设置相同,只是流过不同的数据。最终结果是下面的代码。

Option Explicit
Dim objIE, objShell, objShellWindows
Dim strIDNum, strURL, strWindow, strURLFound, WShell, i

strURL = "http://www.myworkplace.com"
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

WShell.AppActivate strWindow

WScript.Sleep 300

strIDNum = objIE.document.getElementByID("ID_PlaceHolder").innertext

正如您在最后一行中看到的,我还使用innertext而不是value获取 ID 号。

于 2013-12-20T18:35:36.937 回答