Click here to Skip to main content
15,886,676 members
Please Sign up or sign in to vote.
2.20/5 (3 votes)
See more:
Hey, I want to save images from WebBrowser control Directly and not using webclient or HttpWebRequest or even the image URL... the problem is when I try to download an image using its URL some images return 403 error Forbidden because I need to be Signed in to the site. So I need to download using an already signed in WebBrowser control, I've tried to Download image using WebClient and HttpWebRequest by copying WebBrowser Cookies, logining in Using "POST" to login page... But all that didn't work, So I need to Download images directly from WebBrowser without the need to download them again after page load.
Thanks!
Posted

1 solution

There is no such thing as "downloading from WebBrowser control". If something is rendered in a WebBrowser, it is already downloaded. It looks like you just need to obtain the images in some files on your local drive. If has nothing to do with a browser, as you probably understand yourself, you really need to use WebClient or HttpWebRequest (I would advise the second one), but do it correctly. Also, most likely, Web browser cookies, are, most likely, irrelevant. Here is the logic: in first place, you did not have any cookies, but yet you managed to download it all. Instead of cookies, you need to pay attention for authentication itself, through proper credentials. Please see:
http://stackoverflow.com/questions/19764113/how-to-use-httpwebrequest-credentials-property-for-basic-authentication[^],
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.credentials%28v=vs.110%29.aspx[^].

That said, you just need to reproduce exact same client-side action in an HTTP protocol as your browser did. But what to do if you are confusing something which you cannot identify? That often happens in some more tricky situations. I can see two ways to address it:
  1. Look at the page source very thoroughly and find out what exactly it does. You can do it in a browser using something like "View Page Source".
    It can be just some anchor, but it can also be an HTML form, with HTTP parameters passed with name-value keys, according to then name attributes of the controls of the form; it could be AJAX calls; and then you would need to download all Javascript code and see what it does.
  2. Alternatively, you can use some HTTP spy software and analyze all HTTP requests coming through. It's a pretty simple way when you can ignore many unrelated detail. I, for example, use "HttpFox", a plug-in to the Mozilla browser, but it can be anything else. Such tools are very powerful for Web scraping.


—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900