程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> asp采集-ASP采集小偷,指定數據無法抓取

asp采集-ASP采集小偷,指定數據無法抓取

編輯:編程綜合問答
ASP采集小偷,指定數據無法抓取

http://chaxun.ttk.cn:8084/BarScanRecord/trackInfo_jsp.jsp?expBill=560230596486&opeCate=2
頁面裡我只想偷取,當前狀態:已簽收,但一直無法實現,請指教以下為小偷代碼

 <%
  '功能:asp采集代碼
   'url="http://www.kuaidi100.com/query?type=tiantian&postid=560230596486"
url="http://chaxun.ttk.cn:8084/BarScanRecord/trackInfo_jsp.jsp?expBill=560230596486&opeCate=3"  
  str=getHTTPPage(url)
  title=strcut(str,"簽收網點","66",2)
  content=strcut(str,"跟蹤","圖片",2)  
  response.write "標題<br><b>"&title&"</b><br><br><br>內容:<br>"&content  
%>
<%
Function getHTTPPage(url) 
    On Error Resume Next
    dim http 
    set http=Server.createobject("Msxml2.XMLHTTP") 
    Http.open "GET",url,false 
    Http.send() 
    if Http.readystate<>4 then
        exit function 
    end if 
    getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
    set http=nothing
    If Err.number<>0 then 
        Response.Write "<p align='center'><font color='red'><b>服務器獲取文件內容出錯</b></font></p>" 
        Err.Clear
    End If  
End Function

Function BytesToBstr(body,Cset)
    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 = Cset
    BytesToBstr = objstream.ReadText 
    objstream.Close
    set objstream = nothing
End Function
'Download by http://www.codefans.net
'截取字符串,1.包括起始和終止字符,2.不包括
Function strCut(strContent,StartStr,EndStr,CutType)
    Dim strHtml,S1,S2
    strHtml = strContent
    On Error Resume Next
    Select Case CutType
    Case 1
        S1 = InStr(strHtml,StartStr)
        S2 = InStr(S1,strHtml,EndStr)+Len(EndStr)
    Case 2
        S1 = InStr(strHtml,StartStr)+Len(StartStr)
        S2 = InStr(S1,strHtml,EndStr)
    End Select
    If Err Then
        strCute = "<p align='center'>沒有找到需要的內容。</p>"
        Err.Clear
        Exit Function
    Else
        strCut = Mid(strHtml,S1,S2-S1)
    End If
End Function
%>

最佳回答:


請求錯頁面了,你的那個頁面是用ajax動態加載數據的,要請求http://chaxun.ttk.cn:8084/BarScanRecord/search.jsp這個頁面,發送code='560230596486'&opecate=7&ope=domore數據,不過返回的是16進制的編碼內容,需要用jscript做中間體來解碼和讀取json內容。

<script runat="server" language="jscript">
    var o = false;
    function getKV(str, key) {
        if (!o) {
            try {
                o = eval('(' + str + ')');
                if (o.result && o.result.length > 0) {
                    o = eval('(' + o.result[0] + ')');
                    o = o[0];
                }
            }
            catch (ex) { Response.Write(ex.Message + "|EVAL ERROR");o = {}}
        }
        return o[key] || '';
    }
</script>
<%
url="http://chaxun.ttk.cn:8084/BarScanRecord/search.jsp?code=%27560230596486%27&opecate=7&ope=domore"'這個地址返回下面的結果
 '{"result":["[{\"\u8FD0\u5355\u7F16\u53F7\":\"560230596486\",\"\u5F55\u5165\u65F6\u95F4\":\"2014-12-01\",\"\u5BC4\u4EF6\u7F51\u70B9\":\"\u65E0\u9521\",\"\u5BC4\u4EF6\u627F\u5305\u533A\":\"\u65E0\u9521\u534E\u4E1C\u5546\u76DF\u57CE\",\"\u6D3E\u4EF6\u627F\u5305\u533A\":\"\u8302\u540D\u9AD8\u5DDE\u5206\u90E8\",\"\u7B7E\u6536\u7F51\u70B9\":\"\u8302\u540D\u5206\u516C\u53F8\",\"\u53D6\u4EF6\u5458\":\"\",\"\u53D6\u4EF6\u65F6\u95F4\":\"2014-12-01 21:29:50\",\"\u6700\u540E\u64CD\u4F5C\u65F6\u95F4\":\"2014-12-04 13:17:31\",\"\u6700\u540E\u64CD\u4F5C\u7F51\u70B9\":\"\u8302\u540D\u9AD8\u5DDE\u5206\u90E8\",\"\u5168\u7A0B\u5141\u8BB8\u65F6\u95F4\":\"\",\"\u5BC4\u4EF6\u4EBA\":\"\u4E8E\u6D77\",\"\u5BC4\u4EF6\u5730\u5740\":\"\u5858\u5357\u8DEF120\u53F7\",\"\u5BC4\u4EF6\u7701\":\"\u6C5F\u82CF\u7701\",\"\u5BC4\u4EF6\u57CE\u5E02\":\"\u65E0\u9521\u5E02\",\"\u5BC4\u4EF6\u533A\u53BF\":\"\u5357\u957F\u533A\",\"\u63A5\u6536\u4EBA\":\"******\",\"\u63A5\u6536\u5730\u5740\":\"\u5357\u5173\u8857\u5174\u8D243\u5DF726\u53F7\",\"\u63A5\u6536\u7701\":\"\u5E7F\u4E1C\u7701\",\"\u63A5\u6536\u57CE\u5E02\":\"\u8302\u540D\u5E02\",\"\u63A5\u6536\u533A\u53BF\":\"\u9AD8\u5DDE\u5E02\",\"\u8FD0\u5355\u72B6\u6001\":\"\u5DF2\u7B7E\u6536\",\"\u5BC4\u4EF6\u4EBA\u7535\u8BDD\":\"15995838872\",\"\u6536\u4EF6\u4EBA\u7535\u8BDD\":\"******\",\"\u53D6\u4EF6\u8D85\u533A\":\"0\",\"\u6D3E\u9001\u8D85\u533A\":\"0\",\"\u53D6\u4EF6\u8D85\u533A\u5730\u5740\":\"\",\"\u6D3E\u9001\u8D85\u533A\u5730\u5740\":\"\",\"\u8BA2\u5355\u53F7\":\"LP00029601851949\",\"VIP\u5BA2\u6237\u7F16\u7801\":\"\",\"VIP\u5BA2\u6237\u7F51\u70B9\":\"\"}]"]} 
str=getHTTPPage(url)
  if str<>"" then
    response.Write getKV(str,"運單狀態")&"<br/>"
    response.Write getKV(str,"寄件網點")&"<br/>"
    response.Write getKV(str,"寄件人")
end if

  %>
<%
Function getHTTPPage(url) 
    'On Error Resume Next
    dim http 
    set http=Server.createobject("Msxml2.XMLHTTP") 
    Http.open "get",url,false 
    Http.send() 
    getHTTPPage=bytesToBSTR(Http.responseBody,"utf-8")
    set http=nothing
    If Err.number<>0 then 
        Response.Write "<p align='center'><font color='red'><b>服務器獲取文件內容出錯</b></font></p>" 
        Err.Clear
    End If  
End Function
Function BytesToBstr(body,Cset)
    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 = Cset
    BytesToBstr = objstream.ReadText 
    objstream.Close
    set objstream = nothing
End Function
%>
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved