我试图通过WebBrowser控件加载某个页面,同时避免在DIV元素中加载不必要的广告横幅,称为“tb”。
我该怎么做?我已经做了一些googling,并找到了一个使用mshtml引用的例子,但是我无法从这个例子中实现它:https://stackoverflow.com/a/1218875
有什么想法吗?
为什么这个不行?
using System;
using mshtml;
using System.Windows.Forms;
namespace Client
{
public partial class Client : Form
{
public Client()
{
InitializeComponent();
HTMLDocumentClass htmldoc = wbBrowser.Document.DomDocument as HTMLDocumentClass;
IHTMLDOMNode node = htmldoc.getElementById("tb") as IHTMLDOMNode;
node.parentNode.removeChild(node);
}
}
}我收到一个错误:
'mshtml.HTMLDocumentClass‘不包含'getElementById’的定义,也找不到接受'mshtml.HTMLDocumentClass‘类型的第一个参数的扩展方法'getElementById’(您缺少使用指令还是程序集引用?)
和:
互操作类型'mshtml.HTMLDocumentClass‘不能嵌入。使用适用的接口.
发布于 2012-06-01 08:06:05
您可以使用以下方法来完成此操作:
IHTMLDocument3 htmldoc = wbCtrl.Document.DomDocument as IHTMLDocument3;
IHTMLDOMNode node = htmldoc.getElementById("xBar") as IHTMLDOMNode;
node.parentNode.removeChild(node);https://stackoverflow.com/questions/10571125
复制相似问题