XMLHTTP利用POST发送表单时提交中文的问题
程序员文章站
2022-05-18 12:52:58
刚才写一个小偷程序,突然发现一旦post中文时抓取不到内容,考虑到中文编码问题,像javascript中的escape()一样,在vbscript中也可以使用这个函数,只需...
刚才写一个小偷程序,突然发现一旦post中文时抓取不到内容,考虑到中文编码问题,像javascript中的escape()一样,在vbscript中也可以使用这个函数,只需要这个发送就可以正常抓取到内容了send("a="&escape(a)&""&escape(b))
完成收工!
附几个小偷常用的function函数
function bytetostr(vin)
dim strreturn,i,thischarcode,innercode,hight8,low8,nextcharcode
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytetostr = strreturn
end function
function geturl(url,poststr)
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open "post", url, false ,"" ,""
.setrequestheader "content-type","application/x-www-form-urlencoded"
.send(poststr)
geturl = .responsebody
end with
set retrieval = nothing
geturl=bytetostr(geturl)
end function
function regexptext(strng,regstr)
dim regex,match,matches,retstr
set regex = new regexp
regex.pattern = regstr
regex.ignorecase = true
regex.global = true
set matches = regex.execute(strng)
for each match in matches
retstr = retstr & match.value & ","
next
regexptext = retstr
set regex=nothing
end function
用法:
dim poststr,getcontent,getarea
poststr = "action=mobile&mobile="&mobilenumber
getcontent = geturl("http://www.ip138.com:8080/search.asp",poststr)
getarea = replace(replace(replace(regexptext(getcontent,"卡号归属地</td>((.|\n)*?)</td>"),"卡号归属地</td>",""),"<td width=* align=""center"" class=tdc2>",""),"</td>,","")
response.write(getarea)
完成收工!
附几个小偷常用的function函数
function bytetostr(vin)
dim strreturn,i,thischarcode,innercode,hight8,low8,nextcharcode
strreturn = ""
for i = 1 to lenb(vin)
thischarcode = ascb(midb(vin,i,1))
if thischarcode < &h80 then
strreturn = strreturn & chr(thischarcode)
else
nextcharcode = ascb(midb(vin,i+1,1))
strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
i = i + 1
end if
next
bytetostr = strreturn
end function
function geturl(url,poststr)
set retrieval = server.createobject("microsoft.xmlhttp")
with retrieval
.open "post", url, false ,"" ,""
.setrequestheader "content-type","application/x-www-form-urlencoded"
.send(poststr)
geturl = .responsebody
end with
set retrieval = nothing
geturl=bytetostr(geturl)
end function
function regexptext(strng,regstr)
dim regex,match,matches,retstr
set regex = new regexp
regex.pattern = regstr
regex.ignorecase = true
regex.global = true
set matches = regex.execute(strng)
for each match in matches
retstr = retstr & match.value & ","
next
regexptext = retstr
set regex=nothing
end function
用法:
dim poststr,getcontent,getarea
poststr = "action=mobile&mobile="&mobilenumber
getcontent = geturl("http://www.ip138.com:8080/search.asp",poststr)
getarea = replace(replace(replace(regexptext(getcontent,"卡号归属地</td>((.|\n)*?)</td>"),"卡号归属地</td>",""),"<td width=* align=""center"" class=tdc2>",""),"</td>,","")
response.write(getarea)