zoukankan      html  css  js  c++  java
  • 页面爬虫(获取其他页面HTML)加载到自己页面

    //前台

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

  • 相关阅读:
    struct resbuf 结构就象LISP里面的表(
    CString互转int
    C++中std::sort/std::stable_sort/std::partial_sort的区别及使用
    *ARX对数据的类型和单位进行转换
    c++常见容器操作
    C++中const关键字的使用方法,烦透了一遍一遍的搜,总结一下,加深印象!!!
    ARX 简单程序(不错的例子)
    ARX对象的一些文字说明
    CAD ObjectARX扩展工具的源码(一)
    CAD ObjectARX扩展工具的源码(三)
  • 原文地址:https://www.cnblogs.com/snake-hand/p/3149656.html
Copyright © 2011-2022 走看看