asp在服务器端获取网页生成的xml文件,并解析

来源:互联网 发布:excel表格提取部分数据 编辑:程序博客网 时间:2024/05/18 01:39

 <!--#include file="autopostlog.asp"-->
<%
'回帖id(pid)
Dim pid
pid=Request.QueryString("pid")

Dim returnurl
  'preurl = Server.URLEncode(request.ServerVariables("HTTP_REFERER"))
  returnurl=request.QueryString("returnurl")
  returnurl="http://bbs.91.cn/"&returnurl
  'Response.End() 


Dim http
Set http=Server.CreateObject("Microsoft.XMLHTTP")
'http.Open "GET","http://localhost/PHPStudy/xmltest.php",False
http.Open "GET","http://bbs.91.cn/bbstoblog.php?pid="&pid,False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send
Dim xml
Set xml=Server.CreateObject("Microsoft.XMLDOM")
xml.Async=False
xml.ValidateOnParse=False
xml.Load(http.ResponseXML)
If xml.ReadyState>2 Then
 Response.Write("文档已经准备就绪。状态:"& xml.ReadyState &"<br>")
 'Response.Write(http.ResponseText)
 'Response.End()
Dim item,i
Set item=xml.getElementsByTagName("ask")
For i=0 To (item.Length-1)
'For i=0 To 0
Dim questiontitle,questioncontent,questionlink,answertitle,answercontent,passportid
Set questiontitle=item.Item(i).getElementsByTagName("questiontitle")
Set questioncontent=item.Item(i).getElementsByTagName("questioncontent")
Set questionlink=item.Item(i).getElementsByTagName("questionlink")
Set answertitle=item.Item(i).getElementsByTagName("answertitle")
Set answercontent=item.Item(i).getElementsByTagName("answercontent")
set passportid=item.Item(i).getElementsByTagName("passportid")
'Response.Write(questiontitle.Item(0).Text)
'Response.Write(questioncontent.Item(0).Text)
'Response.Write("<a href="&questionlink.Item(0).Text&">>>>>>>查看详细</a>")
'Response.Write(answertitle.Item(0).Text)
'Response.Write(answercontent.Item(0).Text)
'Response.Write(passportid.Item(0).Text)
'Response.Write(item.length)
Dim qtitle,qcontent,qlink,atitle,acontent,puid
qtitle=questiontitle.Item(0).Text
qcontent=questioncontent.Item(0).Text
qlink=questionlink.Item(0).Text
atitle=answertitle.Item(0).Text
acontent=answercontent.Item(0).Text
puid=passportid.Item(0).Text


Dim blogid,username
 Dim rs
 Set rs = server.createobject("adodb.recordset")
 rs.open "SELECT TOP 1 * FROM [oblog_user] where puid="&puid&"", conn, 1, 1
 if(not rs.eof) then
  blogid=rs("userid")
  username=rs("username")
  'Response.Write("ccccc")
 else '该用户还位开通blog 
  'Response.Write("dddddd")
  Response.Redirect(returnurl)'用户还没开通blog就直接返回到bbs
  'Response.Redirect("autoreg.asp")
  'Response.Redirect("http://www.qq.com")
 end if
'Response.Write(blogid)
'Response.Write(qtitle)

'Response.Write("<a href="""& link.Item(0).Text &""">"& title.Item(0).Text &"</a><br>")
Next
Else
Response.Write("文档还未准备就绪。状态:"& xml.ReadyState &"<br>")
'bbs写入blog出问题也跳回bbs
Response.Redirect(returnurl)
End If
Set http=Nothing
Set xml=Nothing


'dim xmlDom,userinfo,id_node,id_value,username_node,username_value,password_node,password_value

'URL="http://localhost/asppage/test.xml"
'URL="http://localhost/asppage/test.xml"

'Set xml = Server.CreateObject("Microsoft.XMLHTTP")
'xml.Open "GET", url, False
'xml.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
'xml.Send

'Response.Write(xml.ResponseText)
'Response.End()
'Set xmlDom = server.createObject("microsoft.xmldom")
'xmlDom.async=False
'xmlDom.ValidateOnParse=false

'set  userinfo   =   xmlDom.DocumentElement     
 '   set   id_node=userinfo.childNodes.item(0)    
  '  set   id_value=id_node.childNodes.item(0)
 'set username_node = userinfo.childNodes.item(1)  
    'set username_value=username_node.childNodes.item(0)
 'set password_node=userinfo.childNodes.item(4)
 'set password_value=password_node.childNodes.item(0)

  'Response.Write("</b><br>节点类型:" &id_value.nodeTypeString)     '
 'Response.Write("<br>节点值:" & userinfo.nodeValue) 
 ' Response.Write(username_value.nodeValue)
  'Response.Write(password_value.nodeValue)
'if xmlDom.ReadyState>2 Then 
'set oItem=xmlDom.getElementsByTagName("item")

'for i=0 to oItem.length-1
'response.write "<SPAN Class='txt'>" & oItem(i).childNodes(0).text & "</SPAN><BR>"


'title=oItem.childNodes.item(0).text
'Link=oItem.childNodes.item(1).text
'pubdate=oItem.childNodes.item(4).text
'next
'end if
%>

原创粉丝点击