How to get image from WebBrowser control

瘦欲@ 提交于 2019-12-11 22:16:42

问题


I have a WebBrowser control, after navigating a page I need to download the image. I used the following code:

HtmlElementCollection tagsColl = webBrowser1.Document.GetElementsByTagName("img");
foreach (HtmlElement currentTag in tagsColl)
{
     ...
     using (var client = new WebClient())
     {
           ...
           client.DownloadFile(currentTag.GetAttribute("src"), path);
           ...
     }
}

but, in this case webclient starts a new session, and link in new session is not correct. I need to do this in same session as webbrowser, only in this case i get a correct link to the image.

How can I do this?


回答1:


Try downloading the image using URLDownloadToFile, which should give you the same session and cache as used by WebBrowser.



来源:https://stackoverflow.com/questions/18992562/how-to-get-image-from-webbrowser-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!