用IHTMLElementCollection解析带script的html文件,不能解析到

xlz45 2006-08-18 10:14:00
这是html内容:
<html>
<head>
<title>page title</title>
</head>
<script language="javascript">
function loaded()
{   var c = document.all.length;
    var i;
    for(i = 0; i < c; i++)
    {
        spantags.innerhtml = spantags.innerhtml + document.all.item(i).tagname + "<br>";
    }
}
</script>
<body onload="">
<span id="spantags"></span>
</body>
</html>

解析html的代码段,发现不能解析到<script>后面的tag,get_length为4,应该是6
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IHTMLElement> pElement;
CComPtr<IHTMLElementCollection> pElementCol;
CComPtr<IHTMLElementCollection> pElementCol2;

pDoc2 = GetHtmlDocument();

HRESULT hr = pDoc2->get_all(&pElementCol);
long i;
pElementCol->get_length(&i);

请各位高手赐教,thx!
...全文
630 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlz45 2006-08-25
  • 打赏
  • 举报
回复
已经解决,谢谢各位
蒋晟 2006-08-21
  • 打赏
  • 举报
回复
get_scripts, not get_all
xlz45 2006-08-20
  • 打赏
  • 举报
回复
是不是用vc6就不能解析带有<script>节点的html文件哪?
应该有升级的mshtml吧。
xlz45 2006-08-20
  • 打赏
  • 举报
回复
to: jiangsheng(蒋晟.Net[MVP])
可能我说的不是很清楚,现在的问题是IHTMLDocument2没有历遍到整个的html文件,在<script>处就断开了,而并不是要对<Script>脚本的执行。
amingo 2006-08-19
  • 打赏
  • 举报
回复
up to u
蒋晟 2006-08-19
  • 打赏
  • 举报
回复
There _is_ a get_scripts() method in IHTMLDocument2 that returns a collection of all the SCRIPT elements in the document, and from there you can get an IHTMLScriptElement for each item. But there isn't any method in IHTMLScriptElement where you can actually execute the functions within the tags (you can get the DISPID of the desired function by calling GetIDsOfNames() from the script peoperty of IHTMLDocument2 with the name of the function, then calling Invoke() with the
parameters).

3,056

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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