怎样把页面源文件转化成DOMDocument?

zyx_ll 2010-05-27 03:37:18
用XMLHttp得到页面代码如下:
-------------------------------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
</head>

<body>
<table width="200" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
<tr>
<td>4</td>
<td><img src="beauty.jpg" width="405" height="550" /></td>
<td>6</td>
</tr>
<tr>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>

</body>
</html>

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

怎样把它转化成一个DOMDocument对象?
我试过了,如果它里边没有那个图片的话就可以,要不然就不行,该怎么办啊?
没图片的话,直接用DOMDocument.loadXML(XMLHttp.responseText)就可以了
有的话就加载不成功,怎么办?
...全文
153 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyx_ll 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 toury 的回复:]
引用 2 楼 zyx_ll 的回复:

引用 1 楼 toury 的回复:
eval('(" &amp;amp; xhr.responseText &amp;amp; ")')


同学,你在说什么?

不懂eval()?
google: VB eval 引用
[/Quote]


可是这个...跟转换成DOM有啥关系呢?
能说详细点儿不?
zyx_ll 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sysdzw 的回复:]
你想干嘛 想以dom方式访问啊,如果是这样就内置个webbrowser,然后webbrowser1.document.body.innerhtml=xxx应该就可以了
[/Quote]

webbrowser效率太低
lidong5144 2010-05-28
  • 打赏
  • 举报
回复
好像可以先把它存为一个文件夹,在进行装载.
lidong5144 2010-05-28
  • 打赏
  • 举报
回复
好像可以先把它存为一个文件夹,在进行装载.
lidong5144 2010-05-28
  • 打赏
  • 举报
回复
顶..
toury 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zyx_ll 的回复:]

引用 1 楼 toury 的回复:
eval('(" &amp; xhr.responseText &amp; ")')


同学,你在说什么?
[/Quote]
不懂eval()?
google: VB eval 引用
无·法 2010-05-28
  • 打赏
  • 举报
回复
你想干嘛 想以dom方式访问啊,如果是这样就内置个webbrowser,然后webbrowser1.document.body.innerhtml=xxx应该就可以了
zyx_ll 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 toury 的回复:]
eval('(" & xhr.responseText & ")')
[/Quote]

同学,你在说什么?
zyx_ll 2010-05-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 toury 的回复:]
呵呵,是我想当然了。用eval()的话需要对返回的字串做很多处理,划不来。

这样:
'引用HTML Object 库
Dim DOM As MSHTML.HTMLDocument
Dim obj As Object
Set obj = CreateObject("htmlfile")
obj.open
obj.write XMLHttp.responseTex……
[/Quote]

哥们儿你太牛X了,本来我刚才找到了问题
把HTML里边非XML的标签去掉就可以了
不过你这样更方便了.多谢多谢~~~
toury 2010-05-28
  • 打赏
  • 举报
回复
呵呵,是我想当然了。用eval()的话需要对返回的字串做很多处理,划不来。

这样:
'引用HTML Object 库
Dim DOM As MSHTML.HTMLDocument
Dim obj As Object
Set obj = CreateObject("htmlfile")
obj.open
obj.write XMLHttp.responseText
Set DOM = obj
=======================
你顶楼的做法是XMLDOM,只能使用getElementsByTagName,很不爽;用HTML的HTMLDocument,可以完全使用众多的方法,如:getElementByID,getElmentsByname。。。。。。。。
toury 2010-05-27
  • 打赏
  • 举报
回复
eval('(" & xhr.responseText & ")')

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧