提取验证码到winform上webbroswer和axwebbroswer
生活随笔
收集整理的這篇文章主要介紹了
提取验证码到winform上webbroswer和axwebbroswer
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
在網(wǎng)上只有webbroswer的代碼,所以自己又修改了修改改成axwebbroswer的
public static class yanZhengMaHelp{//webbrowser驗(yàn)證碼public static Image GetRegCodePic(WebBrowser wbMail, string ImgName, string Src, string Alt){HTMLDocument doc = (HTMLDocument)wbMail.Document.DomDocument;HTMLBody body = (HTMLBody)doc.body;IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();IHTMLControlElement Img;if (ImgName == "") //如果沒(méi)有圖片的名字,通過(guò)Src或Alt中的關(guān)鍵字來(lái)取 {int ImgNum = GetPicIndex(wbMail, Src, Alt);if (ImgNum == -1){return null;}Img = (IHTMLControlElement)wbMail.Document.Images[ImgNum].DomElement;}elseImg = (IHTMLControlElement)wbMail.Document.All[ImgName].DomElement;rang.add(Img);rang.execCommand("Copy", false, null);Image RegImg = Clipboard.GetImage();Clipboard.Clear();return RegImg;}public static int GetPicIndex(WebBrowser wbMail, string Src, string Alt){int imgnum = -1;for (int i = 0; i < wbMail.Document.Images.Count; i++) //獲取所有的Image元素 {IHTMLImgElement img = (IHTMLImgElement)wbMail.Document.Images[i].DomElement;if (Alt == ""){if (img.src.Contains(Src)) return i;}else{if (!string.IsNullOrEmpty(img.alt)){if (img.alt.Contains(Alt)) return i;}}}return imgnum;}//axwebbroswer 驗(yàn)證碼 提取public static Image GetRegCodePic(AxWebBrowser axwbMail, string ImgName, string Src, string Alt){HTMLDocument doc = (HTMLDocument)axwbMail.Document;HTMLBody body = (HTMLBody)doc.body;IHTMLControlRange rang = (IHTMLControlRange)body.createControlRange();IHTMLControlElement Img;if (ImgName == "") //如果沒(méi)有圖片的名字,通過(guò)Src或Alt中的關(guān)鍵字來(lái)取 {Img = (IHTMLControlElement)GetPicIndex(axwbMail, Src, Alt);if (Img == null){return null;}}else{Img = (IHTMLControlElement)doc.getElementsByName(ImgName).item(null, 0);}rang.add(Img);rang.execCommand("Copy", false, null);Image RegImg = Clipboard.GetImage();Clipboard.Clear();return RegImg;}public static IHTMLImgElement GetPicIndex(AxWebBrowser axwbMail, string Src, string Alt){HTMLDocument doc = (HTMLDocument)axwbMail.Document;foreach (IHTMLImgElement img in (IHTMLElementCollection)doc.getElementsByTagName("img")) //獲取所有的Image元素 {if (Alt == ""){if (img.src.Contains(Src)) return img;}else{if (!string.IsNullOrEmpty(img.alt)){if (img.alt.Contains(Alt)) return img;}}}return null;}轉(zhuǎn)載于:https://www.cnblogs.com/weiwin/p/3868576.html
總結(jié)
以上是生活随笔為你收集整理的提取验证码到winform上webbroswer和axwebbroswer的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 记录腾讯云中矿机病毒处理过程(重装系统了
- 下一篇: android node