简体   繁体   中英

How to save webpage with css and js files from C# webbrowser?

I tried to save rendered C# web browser to my hdd. But it only save html source only, no css or jquery js file. I tried with 3 methods.

  1. It only creates only html file without any css, and jquery js files. File.WriteAllText(myDocumentPath, webBrowser5.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(webBrowser5.Document.Encoding));

2.It only creates content text. No html, css, js File.WriteAllText(@"text.txt", webBrowser5.Document.Body.InnerText);

3.It creates bigger html file, still no css or jquery js files writer.Write(webBrowser5.DocumentText);

    private void button1_Click(object sender, EventArgs e)
    {
        String source = ("viewsource.html");
        StreamWriter writer = File.CreateText(source);
        String myDocumentPath = System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\111.html";

        //It only creates only html file without any css, and jquery js files.
        File.WriteAllText(myDocumentPath, webBrowser5.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(webBrowser5.Document.Encoding));

        //it only creates content text
        File.WriteAllText(@"text.txt", webBrowser5.Document.Body.InnerText);

        //It creates bigger html file, still no css or jquery js files
        writer.Write(webBrowser5.DocumentText);
        writer.Close();
    }

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