手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >页面爬虫(获取其他页面HTML)加载到自己页面示例
页面爬虫(获取其他页面HTML)加载到自己页面示例
摘要:复制代码代码如下://前台$(document).ready(function(){varurl="@Url.Action("GetPage...

复制代码 代码如下:

//前台

<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);

}

【页面爬虫(获取其他页面HTML)加载到自己页面示例】相关文章:

.net的常规命名规范示例

asp.net微软图表控件使用示例代码分享

asp.net下Request.QueryString取不到值的解决方法

.net获取本机公网IP地址示例

asp.net页面防止重复提交示例

ASP.NET 2.0 中的创建母版页

在ASP.net中保存/取出图片入/从SQL数据库

ASP.NET编程中的十大技巧

ASP.NET取得所有颜色值示例

ASP.NET连SQL7接口源代码

精品推荐
分类导航