简体   繁体   中英

How to get image from WebBrowser control

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?

尝试使用URLDownloadToFile下载图像,这将为您提供与WebBrowser相同的会话和缓存。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM