您好我正在使用代码获取引荐网址,如下所示:
sRef = encode(Request.ServerVariables("HTTP_REFERER"))
此代码获取以下网址:http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349
从那个网址我想抓住ADV和LOC(Request.querystring不起作用)
有关我如何做到这一点的任何帮助吗?所有这些都发生在脚本中。
答案 0 :(得分:3)
将sRef视为字符串并使用Mid获取值。以下代码应该是您到达目的地的起点!
<%
sRef="http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349"
a=instr(sRef, "adv")+4
b=instr(sRef, "&loc")
response.write(mid(sRef ,a,b-a))
response.write("<br>")
response.write(mid(sRef ,b+5))
%>
答案 1 :(得分:1)
我无法相信我已经这样做了。 ASP Classic是我的第一个网络编程爱,所以我不得不:)
<%
URL="http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349&websync=ert4545445&put=4563"
Response.write ("adv = " + GetVarValue(URL, "adv"))
response.write("<br>")
Response.write ("loc = " + GetVarValue(URL, "loc"))
response.write("<br>")
Response.write ("adv = " + GetVarValue(URL, "websync"))
response.write("<br>")
Response.write ("gput = " + GetVarValue(URL, "gput"))
response.write("<br>")
Response.write ("put = " + GetVarValue(URL, "put"))
response.write("<br>")
%>
<br><br><br>
<%
function GetVarValue(Source, VarName)
pos1 = instr(source, varname + "=")
'to check if the variable was not found
if pos1=0 then
GetVarValue="Not Found!!!"
exit function
end if
pos1 = pos1 + len(varName) + 1
pos2=instr(mid(source,pos1), "&")-1
'to check if it was the last variable
if pos2=-1 then
str1 = mid(source, pos1)
else
str1 = mid(source, pos1, pos2)
end if
GetVarValue=str1
End Function
%>
在页面中使用此功能,您可以通过将变量名称和URL字符串传递给GetVarValue来查询任何变量!
(PS:如果这个答案有效,请接受这个答案,它会对我的StackOverflow Repo产生奇迹:))
答案 2 :(得分:0)
使用Regexp和字典从字符串中提取结构化信息:
>> Dim s : s = "http://www.rzammit.com/pages/linux-form.asp?adv=101&loc=349"
>> Dim d : Set d = getKVP(s)
>> WScript.Echo "loc =", d("loc")
>> WScript.Echo "adv =", d("adv")
>> Function getKVP(s)
>> Dim r, d, m
>> set r = New RegExp
>> r.Global = True
>> r.Pattern = "(\w+)=(\w+)"
>> set d = CreateObject("Scripting.Dictionary")
>> For Each m In r.Execute(s)
>> d(m.SubMatches(0)) = m.SubMatches(1)
>> Next
>> Set getKVP = d
>> End Function
>>
loc = 349
adv = 101
你可能不得不修改简单模式,但这种方法比Instr方式更好。