Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vbscript使用InStr查找URL中变化的信息_Url_Vbscript - Fatal编程技术网

vbscript使用InStr查找URL中变化的信息

vbscript使用InStr查找URL中变化的信息,url,vbscript,Url,Vbscript,我有一个项目,用户在其中调出一个特定的URL,其中Dept、Queue和Day的值根据他们选择的超链接而变化。例如,他们会单击一个超链接,URL类似于: http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptOne&Queue=18&Day=0 下一个超链接可以是: http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFive&Queu

我有一个项目,用户在其中调出一个特定的URL,其中Dept、Queue和Day的值根据他们选择的超链接而变化。例如,他们会单击一个超链接,URL类似于:

http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptOne&Queue=18&Day=0

下一个超链接可以是:

http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFive&Queue=13&Day=9

我想使用
InStr
在URL中查找Dept、Queue和Day,然后将它们的值设置为变量,例如
UDept
UQueue
UDay
。根据这些值,用户可以复制一个特定的ID号,该ID号只能在具有这些值的URL上找到。最终结果将是搜索URL:

http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=UDept&Queue=UQueue&Day=UDay

以下是我目前的代码:

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

strURL = "http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptOne&Queue=18&Day=0"
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").value

提前感谢所有能够帮助我的人。

您考虑过使用正则表达式吗

dim re, s
dim matches

s = "http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFive&Queue=13&Day=9"

Set re = new RegExp
re.Pattern = ".*?Dept=(\w+)&Queue=(\d+)&Day=(\d+)$"
Set matches = re.Execute(s)

Dim uDept, uQueue, uDay
uDept = matches(0).submatches(0)
uQueue = matches(0).submatches(1)
uDay = matches(0).submatches(2)

Msgbox join(array("uDept = " & uDept, "uQueue = " & uQueue , "uDay = " & uDay), vbNewLine)

' Output:
' uDept = DeptFive
' uQueue = 13
' uDay = 9
要替换,还可以使用正则表达式:

Set re = new RegExp
s = "http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFive&Queue=13&Day=9"
newDept = "DeptFourtyTwo"
newQueue = 404
newDay = 12

re.Pattern = "(Dept=)\w+"
newUrl = re.Replace(s, "$1" & newDept)
re.Pattern = "(Queue=)\d+"
newUrl = re.Replace(newUrl, "$1" & newQueue)
re.Pattern = "(Day=)\d+"
newUrl = re.Replace(newUrl, "$1" & newDay)

msgbox newUrl
' output:
' http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFourtyTwo&Queue=404&Day=12

' Alternatively you can replace everything at once if the order and presence of
' parameters is guaranteed:
re.Pattern = "(Dept=)\w+(&Queue=)\d+(&Day=)\d+"
MsgBox re.Replace(s, "$1DeptFourtyTwo$2404$312")     

这仅使用Instr和Mid函数

s="http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=DeptFive&Queue=13&Day=9"

  a = InStr(s, "?") 'We get the value until ?

    d1 = Mid(s, a)

    c1 = InStr(d1, "=")

    c2 = InStr(d1, "&")

    d2 = Mid(d1, c2 + 1)
    d3 = Mid(d1, c1 + 1, (c2 - c1) - 1) 'value of Dept is d3



    c3 = InStr(d2, "=")
    c4 = InStr(d2, "&")
    d5 = Mid(d2, c4 + 1)

    d4 = Mid(d2, c3 + 1, (c4 - c3) - 1) 'value of Queue is d4

    c6 = InStr(d5, "=")
    d6 = Mid(d5, c6 + 1) ' Value of Day is d6

希望这有帮助

我想我需要的是一种从Internet Explorer获取URL文本的方法,找到部门、队列和日期,将它们设置为变量,然后将其设置为strURL。我想要
http://www.myworkplace.com/UserPlatform/User/Process.aspx?Dept=UDept&Queue=UQueue&Day=UDay
更像一个常量,从UDept、UQueue和UDay的URL获取数据后,设置它们并将其用于strURL。这可能吗?好的,我知道你是如何改变变量的,但是如果在你的例子中,你不知道
s
?比如说,为了有一个用来收集数据的URL,你必须用窗口标题“Workflow Process”转到Internet Explorer,获取该窗口的URL,并将其设置为
s
…这可能吗?现在我想了想,如果我能捕获名为“工作流流程”的窗口的URL,我就不需要获取部门、队列和日期。也许你必须弄清楚你真正的问题是什么,然后在新问题中提问。到目前为止,我试图帮助您解答您的问题
“我想使用InStr在URL中查找Dept、Queue和Day,然后将它们的值设置为变量,例如UDept、UQueue和UDay”
,并向您展示了另一种方法,即如何使用正则表达式捕获和替换字符串中的某些文本部分。