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

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

本文介绍asp 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="http://www.sto.cn:8888/sto/index.jsp?"
senddata="wen="&s_id
return_htm=PostHttpPage("http://www.sto.cn/",sendurl,senddata,"utf-8")
response.Write(return_htm)

 

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

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值