Copy codeThe Code is as follows:
// Front-end
<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 ();
}
});
});
// Background
// Crawler nature, send URL request, return the entire page 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 );
}