使用以下代码将外部网页(html)加载到字符串变量中:
WebClient webpage = new WebClient();
string url = "<url to page>";
//remove <div class="yr-footer lp_footer"/>
//string html = webpage.DownloadString(url);//.Replace("\n", "").Replace("\r","").Replace("\t","").Replace("\"","'");
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
我如何操纵结果(html变量)来隐藏除了我要显示的特定div之外的所有内容?
答案 0 :(得分:0)
找到解决方案。通过在视图/局部视图中添加jQuery将字符串传递给视图/局部视图后将其删除:
<script>
$(".class1").remove();
$(".class2").remove();
$(".class3").remove();
$(".class4").remove();
$(".class5").remove();
</script>
使用该名称可能同样适用
<script>
$("#Name1").remove();
$("#Name2").remove();
$("#Name3").remove();
$("#Name4").remove();
$("#Name5").remove();
</script>