ScrapySharp icon indicating copy to clipboard operation
ScrapySharp copied to clipboard

Downloading resource files

Open mpaine-act opened this issue 5 years ago • 1 comments

How do you use ScrapingBrowser to download web resource files? I would love this feature but don't see how to save to disk.

For example, I am able to achieve this by adding to ScrapingBrowser:

    public WebResource DownloadWebResourceFile(Uri url, string path, FileMode mode)
    {
        var response = ExecuteRequest(url, HttpVerb.Get, new NameValueCollection());
        var stream = new FileStream(path, mode);
        var responseStream = response.GetResponseStream();

        if (responseStream != null)
            responseStream.CopyTo(stream);

        responseStream.Close();
        return new WebResource(stream, response.Headers["Last-Modified"], url, !IsCached(response.Headers["Cache-Control"]), response.ContentType);
    }

Thank you.

mpaine-act avatar Jun 23 '20 01:06 mpaine-act

I think, what you need is stream. you can save bytes of stream to disk. Url will give you file name and extension.

gbthakkar avatar Jun 23 '20 05:06 gbthakkar