当前位置: 移动技术网 > IT编程>开发语言>.net > ASP编程实现各家快递公司订单状态查询

ASP编程实现各家快递公司订单状态查询

2018年09月30日  | 移动技术网IT编程  | 我要评论

广州东苑宾馆,河北北方学院论坛,酷站

本文介绍 xmlhttp异步读取、提交数据到远程服务器,通过此原理可以实现类似文章采集、图片采集、天气预报等功能。

废话少说,直接贴上代码,以申通快递查询为从例,其它公司的原理一样

------------------

search.htm

------------------

<form target="_blank" action="sto.asp" method="get">
              快件号:
              <input name="s_id" type="text" id="s_id">
                  <input name="submit4" type="submit" value="查询">
</form>

 

------------------

sto.asp

------------------

'========================================================================
'字符编码函数
'========================================================================
function bytestobstr(body,code)
        dim objstream
        set objstream = server.createobject("adodb.stream")
        objstream.type = 1
        objstream.mode =3
        objstream.open
        objstream.write body
        objstream.position = 0
        objstream.type = 2
        objstream.charset =code
        bytestobstr = objstream.readtext 
        objstream.close
        set objstream = nothing
end function
'====================================================================

 

'==================================================================
'提交参数

'==================================================================
function posthttppage(loginurl,loginacturl,postdata,charsets)
    dim xmlhttp
    dim retstr     
    set xmlhttp = createobject("microsoft.xmlhttp") 
    xmlhttp.open "post", loginacturl, false
    xmlhttp.setrequestheader "content-length",len(postdata)
    xmlhttp.setrequestheader "content-type", "application/x-www-form-urlencoded"
    xmlhttp.setrequestheader "referer", loginurl
    xmlhttp.send postdata
    posthttppage=bytestobstr(xmlhttp.responsebody,charsets)
    set xmlhttp = nothing
end function

 

dim gethtm,sendurl,senddata,return_htm,s_id,s_code
if(request.querystring("s_id")<>"") then
 s_id=request.querystring("s_id")
else
 response.write("请输入订单号")
 response.end
end if
s_code=request.querystring("s_code")
sendurl="https://www.sto.cn:8888/sto/index.?"
senddata="wen="&s_id
return_htm=posthttppage("https://www.sto.cn/",sendurl,senddata,"utf-8")
response.write(return_htm)

 

原理大概是提交数据到申通的查询入口,获取返回的htm代码,现在返回的完全是申通的网页代码,你可以使用字符截取函数只显示实际订单的数据,其它的页面代码过滤掉就可以实现像https://www.ekaid.com/这样的查询效果了,其它快递公司的查询以此类推,需要注意的就是不同快递公司的网站采取的编码不同,一般是utf-8,和gb2312,可以通过源查对方源代码中的

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

看出charset的设置是什么编码格式。ok,以上代码稍加修改就可以实现天气预报、新闻采集等功能,请读者自行调试。

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网