以下的ASP語法可透過ISBN找到博客來的書籍圖片及簡介
<%
'建立物件
Set xml2 = Server.CreateObject ("Microsoft.XMLHTTP")
Set outXML = Server.CreateObject("Microsoft.XMLDOM") 'Microsoft.XMLDOM物件
isbn="put your isbn"
'產生博客來網址
outurl="http://search.books.com.tw/exep/prod_search.php?cat=all&key=" & isbn
xml2.open "GET", outurl, false
xml2.send
'取博客來內容並轉碼
outXML=bytes2BSTR(xml2.responsebody)
IF xml2.status=200 Then '頁面連線正常
'找書籍內容位置
cpos=Instr(1,outXML,"checkbox")
If cpos<>0 then '在博客來中找到ISBN的書
'照圖片超連結
ppos=Instr(cpos,outXML,"rc=")
ppoe=Instr(ppos,outXML,"/>")
picpo=mid(outXML,ppos,ppoe-(ppos))
'去除圖片大小資訊
picpo=mid(picpo,5,Instr(1,picpo,"&")-5)
'輸出圖片,圖片大小請設定於第二次的width=
response.write "<a href='" & picpo & "&width=300' target=_blank>" & "<img src='" & picpo & "&width=160' />" & "</a>"
'讀取內容簡介
cpoe=Instr(cpos+1,outXML,"more</a></span>")+4
cpos=InStrRev(outXML,"<p>",cpoe)
bookdata =striptags(mid(outxml,cpos,cpoe-cpos+4))
'輸出內容
Response.Write "內容簡介:<BR>" & bookdata
response.write "<BR>(資料來源:博客來網路書局)"
Else '博客來中找不到ISBN '
Response.Write "查無本書資訊"
End if
ELSE
Response.Write "連線發生錯誤,代碼:" & xml2.status
END IF
'去超連結標籤
Function stripTags(strToStrip )
Dim objRegExp
strToStrip = Trim( strToStrip & "" )
If Len( strToStrip ) > 0 Then
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern= "<[^>]+>"
strToStrip = objRegExp.Replace(strToStrip, "")
Set objRegExp = Nothing
End If
stripTags = strToStrip
End Function
'字碼互轉函數
Function bytes2BSTR(vIn)
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
bytes2BSTR = strReturn
End Function
%>
留言列表