complete html (after javascript execution) in web api

325 Views Asked by At

I have a script tag e.g

<script>document.write(<p>This is a test</p>)</script> 

as a string, so I need the full html(when it will load on web browser) as string in web api method For eg

 public string GetHTML()
    {
        string script = "<script>document.write(<p>This is a test</p>)</script>";
        string html = "<html><head></head><body><script>document.write(\" <p> Hiiiiiiiii </p> \")</script><p>Hiiiiiiiii</p></body></html>";//Here i want some processing which return this kind of value
        return html;
    }

I have tried most of the things like convert the view into string, create a request with webclient to view but I got the html without javascript executed.

I have also look into headless browsers but couldn't get it compatible with webapi.

UPDATE 23/Sep/2016 : I pardon that I am unable to clear the question.Actually it is not much more related to mvc or web api .My core requirement is that i have a html string as described above so i need a c# code to get the html which have javascript executed. For e.g.

 string Inputhtml = "<html><head></head><body><script>document.write(\" <p>Hiiiiiiiii</ p > \")</script></body></html>";
            string Outputhtml = "<html><head></head><body><script>document.write(\" <p>Hiiiiiiiii</ p > \")</script><p>Hiiiiiiiii</p></body></html>";

So in output html there is a p tag which is written by javascript. I hope now question makes more sense.

0

There are 0 best solutions below