复制代码 代码如下:

//前台

<div id=”showIframe”></div>

$(document).ready(function() {

var url = “@Url.Action(“GetPagehtml“,”Catalog”)”;

$.ajax({

url: url,

type: “POST”,

dataType:”json”,

data: { url: “http://www.baidu.com” },

error: function () {

alert(“bbb”);

},

success: function (data) {

$(“#showIframe”).append(data);

//$(“#showIframe div”).hide();

//$(“#showIframe>#container”).show();

//$(“#showIframe>#container>#content”).show();

//$(“#showIframe>#container>#content>.cmsPage”).show();

}

});

});

//后台

//爬虫本质,发送URL请求,返回整个页面HTML

[HttpPost]

public JsonResult GetPageHtml(string url)

{

string pageinfo;

try

{

HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(url);

myReq.Accept = “image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*”;

myReq.UserAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)”;

HttpWebResponse myRep = (HttpWebResponse)myReq.GetResponse();

Stream myStream = myRep.GetResponseStream();

StreamReader sr = new StreamReader(myStream, Encoding.Default);

pageinfo = sr.ReadToEnd().ToString();

}

catch

{

pageinfo = “”;

}

return Json(pageinfo);

}
声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。