我想通過WebBrowser控件加載某個頁面,同時避免不必要的廣告橫幅加載名爲'tb'的DIV元素。將頁面加載到WebBrowser控件,同時通過ID跳過HTML元素?
我該怎麼做?我做了一些谷歌搜索,並找到了一個使用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' does not contain a definition for 'getElementById' and no extension method 'getElementById' accepting a first argument of type 'mshtml.HTMLDocumentClass' could be found (are you missing a using directive or an assembly reference?)
和:
Interop type 'mshtml.HTMLDocumentClass' cannot be embedded. Use the applicable interface instead.