public CSWB()
{
InitializeComponent();
this.wbForum.NavigateComplete2 += wbForum_NavigateComplete2;
this.wbForum.LocationChanged += wbForum_LocationChanged;
this.wbForum.BeforeNavigate2 += wbForum_BeforeNavigate2;
this.wbForum.DocumentComplete += wbForum_DocumentComplete;
this.wbForum.ProgressChange += wbForum_ProgressChange;
this.wbForum.DocumentCompleteEX += wbForum_DocumentCompleteEX;
}
void wbForum_DocumentCompleteEX(object sender, csExWB.DocumentCompleteExEventArgs e)
{
Helper.Logger.Instance.Info("wbForum_DocumentCompleteEX");
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
}
void wbForum_ProgressChange(object sender, csExWB.ProgressChangeEventArgs e)
{
Helper.Logger.Instance.Info("wbForum_ProgressChange");
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
}
void wbForum_DocumentComplete(object sender, csExWB.DocumentCompleteEventArgs e)
{
Helper.Logger.Instance.Info("wbForum_DocumentComplete");
Helper.Logger.Instance.Info(e.url.ToString());
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
var doc = (mshtml.HTMLDocument)this.wbForum.WebbrowserObject.Document;
Helper.Logger.Instance.Info(doc.body.innerText);
}
void wbForum_BeforeNavigate2(object sender, csExWB.BeforeNavigate2EventArgs e)
{
Helper.Logger.Instance.Info("wbForum_BeforeNavigate2");
Helper.Logger.Instance.Info(e.url.ToString());
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
}
void wbForum_LocationChanged(object sender, EventArgs e)
{
Helper.Logger.Instance.Info("wbForum_LocationChanged");
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
}
void wbForum_NavigateComplete2(object sender, csExWB.NavigateComplete2EventArgs e)
{
Helper.Logger.Instance.Info("wbForum_NavigateComplete2");
Helper.Logger.Instance.Info(e.url.ToString());
Helper.Logger.Instance.Info(this.wbForum.ReadyState.ToString());
if (e.url == this.wbForum.LocationUrl)
{
Helper.Logger.Instance.Info("页面加载完成");
var doc = (mshtml.HTMLDocument)this.wbForum.WebbrowserObject.Document;
//Helper.Logger.Instance.Info(doc.body.innerText); 本来想在这里修改的,但是这里的Body还是为null
}
}
private void btnLoad_Click(object sender, RoutedEventArgs e)
{
this.wbForum.Navigate2("http://www.baidu.com/cache/user/html/login-1.2.html");
}
private void btnLoad2_Click(object sender, RoutedEventArgs e)
{
this.wbForum.Navigate2("http://tieba.baidu.com/index.html");
}
}我想要的是对浏览器的指定的某些图片或区域进行拦截不让浏览器加截资源
如,
我想对页面中标签为img class为logo的,拦截不显示,
我想对页面中所有的<object>对像不加载
就像一些浏览器的广告拦截功能谢谢,那要在哪个事件下进行处理呢?谢谢
wbForum.WBDOCDOWNLOADCTLFLAG = wbForum.WBDOCDOWNLOADCTLFLAG | (int)DOCDOWNLOADCTLFLAG.NO_RUNACTIVEXCTLS; // 不运行activex如果要拦截特定的图片好像就比较困难了,我再看看
{
wbForum.WBDOCDOWNLOADCTLFLAG = wbForum.WBDOCDOWNLOADCTLFLAG | (int)DOCDOWNLOADCTLFLAG.NO_RUNACTIVEXCTLS; // 不运行activex
wbForum.DownloadImages = false; // 不显示图片
this.wbForum.Navigate2("http://tieba.baidu.com/index.html");
wbForum.DocumentComplete += wbForum_DocumentComplete;
} void wbForum_DocumentComplete(object sender, csExWB.DocumentCompleteEventArgs e)
{
if (e.url != "http://tieba.baidu.com/index.html")
return;
wbForum.DocumentComplete -= wbForum_DocumentComplete;
wbForum.DownloadImages = true; // 允许显示图片
var img = wbForum.GetElementByID(false, "tieba_logo"); // 找到要显示的图片
var src = img.getAttribute("src", 0);
img.setAttribute("src", src, 0); // 刷新
}
在进入
wbForum.DownloadImages = false; // 不显示所有图片
wbForum.WBDOCDOWNLOADCTLFLAG = wbForum.WBDOCDOWNLOADCTLFLAG | (int)DOCDOWNLOADCTLFLAG.NO_RUNACTIVEXCTLS; // 不运行activex
this.wbForum.Navigate2("http://tieba.baidu.com/index.html");这时浏览器会提示:一个或多个ActiveX控件无法显示,原因可能是......所以最好的话还是在Document加载但还没有显示的时候对他进行处理
把我不想显示的内容先去掉万分感谢
访问URL
得到HTML
再根据HTML显示出图片
----------------------
那么在得到HTML的时候,
如是从上加截到最后,当出现img标签的时候,我就判断他是不是满足我的条件
如果不满足我就删除这个标签
话说回来,那样做和让WebBrowser去解析,然后再修改dom,并下载image有多少区别呢?