以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  怎么利用XML提取HTML中的中文  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=55160)


--  作者:zoie
--  发布时间:11/10/2007 7:07:00 PM

--  怎么利用XML提取HTML中的中文

初学XML,想利用XMLHTTTP从诸如google的页面上提取所要的汉字,请问怎么做到呢?

ps:可以做到全部显示google源代码,但是只要其中的如<title>...</title>之间的汉字,怎么做到呢?


--  作者:Qr
--  发布时间:11/10/2007 7:55:00 PM

--  
用javascript就可以,getElementsByTagName("title")
--  作者:zoie
--  发布时间:11/10/2007 8:05:00 PM

--  
谢谢ls。

查到一个用vbscript写成的可显示baidu源码的程序,如果用javascript来做应该怎么写?(语法学的不好,55555555):

-------------------
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<body>
<div id="demo"> <div style="width: 677; height: 70">

</body>

</html>
<script language=vbscript>
 
 
sub b3_onclick  
  Dim objXMLHTTP, xml
  Set xml = CreateObject("Microsoft.XMLHTTP")
  
  xml.Open "GET", "http://www.baidu.com/", False
  ' Pull the data from the web page
  xml.Send
  'demo.innerhtml= xml.responseText
  'demo.innertext= xml.responseText
  demo.innertext= bytes2BSTR(xml.responsebody)
  Set xml = Nothing
end sub

sub d1_select

end sub

Function bytes2BSTR(vIn)
    Dim strReturn
    Dim I, ThisCharCode, NextCharCode
    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

</script>
<input type="button" value="获取html源码" name="B3">

---------------------------


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
31.250ms