我有一个脚本标签,例如
<script>document.write(<p>This is a test</p>)</script>
作为一个字符串,所以我需要完整的 html(当它将在 Web 浏览器上加载时)作为 Web api 方法中的字符串例如
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;
}
我已经尝试了大部分的事情,比如将视图转换为字符串,使用 webclient 创建一个请求来查看,但是我得到了没有执行 javascript 的 html。
我也研究了无头浏览器,但无法使其与 webapi 兼容。
2016 年 9 月 23 日更新:对不起,我无法清除问题。实际上,它与 mvc 或 web api 并没有太大关系。我的核心要求是我有一个如上所述的 html 字符串,所以我需要 ac# 代码获取执行了 javascript 的 html。例如
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>";
所以在输出 html 中有一个 ap 标签,它是由 javascript 编写的。我希望现在的问题更有意义。