灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:9082回复:0

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

楼主#
更多 发布于:2013-07-09 12:57
本文介绍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,以上代码稍加修改就可以实现天气预报、新闻采集等功能,请读者自行调试。

喜欢0 评分0
游客

返回顶部