asp如何跨域读取数据并存入自己的数据库?
例如我要将
http://www.gxcaipiao.com.cn/klsfnt.jsp
这个网页的开奖号码数据取得存入ASP变量,然后更新到我的ACCESS数据库中,请问怎么做?
[解决办法]
<%
url = "http://www.gxcaipiao.com.cn/noticequery_noticeQuery.action?period=2013116&lotterycode=12"
Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
.async = False
.validateOnParse = False
.preserveWhiteSpace = False
.resolveExternals = False
.load url
If .parseError.errorCode <> 0 Then
sErrMsg = .parseError.errorCode & "
[解决办法]
" &_
.parseError.srcText & "
[解决办法]
" & .parseError.reason
Set oDoc = Nothing
Response.Write sErrMsg
Response.End
End If
End With
Set oRoot = oDoc.documentElement
If oRoot.getAttribute("errcode")<>"0000" Then
Response.Write sErrMsg
Response.End
End If
Set oLot = oRoot.selectSingleNode("lottery")
perdid = oLot.getAttribute("perdid")
lottname = oLot.getAttribute("lottname")
awardcode = oLot.getAttribute("awardcode")
awarddate = oLot.getAttribute("awarddate")
s = "名称:" & lottname & " " &_
"期数:" & perdid & " " &_
"开奖号码:" & awardcode & " " &_
"开奖日期:" & awarddate & "<br>"
Set oNodes = oLot.selectNodes("//level")
For i = 0 To oNodes.length-1
s = s & oNodes(i).getAttribute("name") & " " &_
oNodes(i).getAttribute("localcount") & " " &_
oNodes(i).getAttribute("money") & "<br>"
Next
Set oNodes = oLot.selectSingleNode("//pool[@index=1]")
s = s & "销售金额:" & oLot.getAttribute("localsale") & " " &_
"中奖金额:" & oLot.getAttribute("localaward") & " " &_
"未中余额:" & oNodes.getAttribute("money") & "<br>"
Response.Write s
Set oLot = Nothing
Set oNodes = Nothing
Set oDoc = Nothing
%>
<%
url = "http://www.gxcaipiao.com.cn/noticequery_noticeQuery.action?period=2013116&lotterycode=12"
Set oHttp = CreateObject("Msxml2.ServerXMLHTTP")
oHttp.Open "GET", url, False
oHttp.Send
Set oDoc = oHttp.responseXML
Set oHttp = Nothing
With oDoc
.async = False
.validateOnParse = False
.preserveWhiteSpace = False
.resolveExternals = False
If .parseError.errorCode <> 0 Then
sErrMsg = .parseError.errorCode & "
[解决办法]
" &_
.parseError.srcText & "
[解决办法]
" & .parseError.reason
Set oDoc = Nothing
Response.Write sErrMsg
Response.End
End If
End With
Set oRoot = oDoc.documentElement
If oRoot.getAttribute("errcode")<>"0000" Then
Response.Write sErrMsg
Response.End
End If
Set oLot = oRoot.selectSingleNode("lottery")
perdid = oLot.getAttribute("perdid")
lottname = oLot.getAttribute("lottname")
awardcode = oLot.getAttribute("awardcode")
awarddate = oLot.getAttribute("awarddate")
s = "名称:" & lottname & " " &_
"期数:" & perdid & " " &_
"开奖号码:" & awardcode & " " &_
"开奖日期:" & awarddate & "<br>"
Set oNodes = oLot.selectNodes("//level")
For i = 0 To oNodes.length-1
s = s & oNodes(i).getAttribute("name") & " " &_
oNodes(i).getAttribute("localcount") & " " &_
oNodes(i).getAttribute("money") & "<br>"
Next
Set oNodes = oLot.selectSingleNode("//pool[@index=1]")
s = s & "销售金额:" & oLot.getAttribute("localsale") & " " &_
"中奖金额:" & oLot.getAttribute("localaward") & " " &_
"未中余额:" & oNodes.getAttribute("money") & "<br>"
Response.Write s
Set oLot = Nothing
Set oNodes = Nothing
Set oDoc = Nothing
%>
<!--#include file="easp.asp"-->
<%
'需要引入EasyAsp类库,自己网上找,最新版本是2.2
'这个库很好用,建议下来学习,可以节省很多代码
Easp.BasePath = ""
Easp.Use("Http")
Dim url, tmp, s
Dim perdid, lottname, awardcode, awarddate
Dim period, lotterycode
period = "201312017" '期数
lotterycode = "09" '彩票种类 09 表示快乐十分
url = "http://www.gxcaipiao.com.cn/noticequery_noticeQuery.action?period=" & period & "&lotterycode=" & lotterycode
tmp = Easp.Http.Get(url)
perdid = Easp.Http.SubStr("perdid=""", """", "")
lottname = Easp.Http.SubStr("lottname=""", """", "")
awardcode = Easp.Http.SubStr("awardcode=""", """", "")
awarddate = Easp.Http.SubStr("awarddate=""", """", "")
s = "彩票名称:" & lottname & "<br>"
s = s & "期数:" & perdid & "<br>"
s = s & "开奖号码:" & awardcode & "<br>"
s = s & "开奖时间:" & awarddate
Easp.WN s
%>