网站建设资讯

NEWS

网站建设资讯

基于ASP.NET网页如何实现C#数据采集

本篇内容主要讲解“基于ASP.NET网页如何实现C#数据采集”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“基于ASP.NET网页如何实现C#数据采集”吧!

成都创新互联是一家集网站建设,陇西企业网站建设,陇西品牌网站建设,网站定制,陇西网站建设报价,网络营销,网络优化,陇西网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

C#数据采集大体可以分为两部曲:

一部曲:

因为要采集别人网页上的内容,所有我们先要得到要采集网页上的html代码,获取html代码还是比较简单。利用WebClient的DownloadData(url)得带byte数组,然后在转换成string字符串。

具体代码如下:

///  ///获取网页源代码  ///  ///URL路径  ///编码方式  publicstringGetHTML(stringurl,stringencoding)  {  WebClientweb=newWebClient();  byte[]buffer=web.DownloadData(url);  returnEncoding.GetEncoding(encoding).GetString(buffer);  }

二部曲:

现在我们得到了目标网页的html代码,那么我们就开始时得扣取我们想要的数据。扣取数据无疑就要用到强大的正则表达式了。利用正则表达式的匹配来获取我们要的内容,这里可以过滤掉制定的html代码,剩下的就是内容了。

C#数据采集具体代码如下:

Htmlhtml=newHtml();  //得到指定页面的html代码,***个参数为url(貌似都知道),第二个是目标网页的编码集  stringhtmlCode=html.GetHTML("http://gvod.tom59.cn/List.asp?ClassId=3","gb2312");  //正则表达式  Regexregexarticles=newRegex("\\d+)\"\\s+target=\"_blank\">(?.+)</a>.*</td>");  //所有匹配表达式的内容  MatchCollectionmarticles=regexarticles.Matches(htmlCode);  ///遍历匹配内容  foreach(Matchminmarticles)  {  Console.Write("标题:"+m.Groups["title"].Value+"\n");  Console.Write("id:"+m.Groups["id"].Value+"\n");  Console.Write("\n");  }</pre><p>到此,相信大家对“基于ASP.NET网页如何实现C#数据采集”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!</p>            
            
                        <br>
            新闻名称:基于ASP.NET网页如何实现C#数据采集            <br>
            链接地址:<a href="http://scjierui.cn/article/iiscje.html">http://scjierui.cn/article/iiscje.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/docchph.html">c语言中模板函数的优点 c语言有模板函数吗</a>
                </li><li>
                    <a href="/article/docsocc.html">linux创建编辑命令 linux如何创建文件</a>
                </li><li>
                    <a href="/article/docsoco.html">linux的ll命令排序 linux ll命令按时间排序</a>
                </li><li>
                    <a href="/article/docchdj.html">python嵌套go语言 go语言与Python</a>
                </li><li>
                    <a href="/article/docsoop.html">包含c语言中sempty函数的词条</a>
                </li>        </ul>
    </div>
</div>
</div>
<footer>
    <div class="footop">
        <div class="wrap">
            <div class="bottomrpw">
                <div class="erp arp">
                    <dl>
                        <dt>ADDRESS</dt>
                        <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd>
                    </dl>
                </div>
                <div class="erp arp">
                    <dl>
                        <dt>TEL</dt>
                        <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd>
                    </dl>
                </div>
                <div class="erp crp">
                    <dl>
                        <dt>OTHER</dt>
                        <dd> <a class="word get-quote">获得报价与方案</a> </dd>
                        <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd>
                    </dl>
                </div>
                <div class="erp code-rp">
                    <dl>
                        <dt>Wechat</dt>
                        <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="美图齐众微信公众号" /> </span> </dd>
                    </dl>
                </div>
            </div>
        </div>
    </div>
    <div class="footerbot">
        <div class="friendlinks">
            <div class="wrap">
                <ul class="rpl">
                    <li><a href="http://www.cypth.com/" title="成都灯箱广告" target="_blank">成都灯箱广告</a></li><li><a href="http://www.scjiangyou.cn/" title="江油网站建设" target="_blank">江油网站建设</a></li><li><a href="https://www.cdcxhl.com/h5.html" title="h5页面制作" target="_blank">h5页面制作</a></li><li><a href="http://www.cdymzj.com/" title="注册域名" target="_blank">注册域名</a></li><li><a href="http://www.ncjierui.cn/" title="彭山网站制作" target="_blank">彭山网站制作</a></li><li><a href="http://www.dcly116.com/" title="边坡防护网" target="_blank">边坡防护网</a></li><li><a href="http://www.cdhcym.com/" title="成都除甲醛" target="_blank">成都除甲醛</a></li><li><a href="https://www.cdxwcx.com/wangzhan/gaiban.html" title="网站改版" target="_blank">网站改版</a></li><li><a href="http://www.cdwzweihu.com/" title="成都网站维护公司" target="_blank">成都网站维护公司</a></li><li><a href="http://www.whyarui.cn/" title="whyarui.cn" target="_blank">whyarui.cn</a></li>                </ul>
            </div>
        </div>
        <div class="wrap">
            <div class="copyright"> <span class="en">©2025</span> 青羊区美图齐众设计工作室(个体工商户)四川站<span class="en">ALL RIGHTS
                        RESERVED.</span> <a rel="nofollow" href="https://beian.miit.gov.cn" target="_blank">蜀ICP备2025119604号-2</a> </div>
        </div>
    </div>
</footer>
<div class="fcwrap">
    <ul class="rpl clearfix">
        <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i>
            <strong>18980820575</strong> </a> </li>
        <li class="qq"> <a rel="nofollow" target="_blank"
                           href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i>
            <strong>244261566</strong> </a> </li>
        <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i>
            <strong>回到顶部</strong> </a> </li>
    </ul>
</div>
<!--nav-->
<div class="n-Wrap">
    <div class="navBar visble show">
        <div class="barlogo">
            <a href="/" rel="nofollow">
                <img src="/Public/Home/images/logo1.png" alt="四川做网站" />
                <img src="/Public/Home/images/logo2.png" alt="四川网站设计" />
            </a>
        </div>
        <div class="bmenu">
            <i class="bar-top"><span></span></i>
            <i class="bar-cen"><span></span></i>
            <i class="bar-bom"><span></span></i>
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
    </div>
    <section class="fixmenu">
        <div class="close-bar">
            <i class="bar-left"><span></span></i>
            <i class="bar-right"><span></span></i>
        </div>
        <nav class="smph">
            <ul>
                <li class="index-hrefs on"><a href="http://www.scjierui.cn/"><font>首页</font></a></li>
                <li><a href="/about/" rel="nofollow"><font>关于美图齐众</font></a></li>
                <li><a href="/service/" rel="nofollow"><font>服务范围</font></a></li>
                <li><a href="/case/" rel="nofollow"><font>案例展示</font></a></li>
                <li><a href="/solve/" rel="nofollow"><font>解决方案</font></a></li>
                <li><a href="/news/" rel="nofollow"><font>建站资讯</font></a></li>
                <li><a href="/contact/" rel="nofollow"><font>联系美图齐众</font></a></li>
            </ul>
            <div class="pwrap">
                <span class="label">服务热线</span>
                <strong class="phone"><a href="tel:18980820575">18980820575</a></strong>
            </div>
        </nav>
    </section>
</div>
<!--end nav-->
<script src="/Public/Home/js/hotcss.js"></script>
<script type="text/javascript" src="/Public/Home/js/su_new.js"></script>
</body>
</html>
<script>
    $(".con img").each(function(){
        var src = $(this).attr("src");    //获取图片地址
        var str=new RegExp("http");
        var result=str.test(src);
        if(result==false){
            var url = "https://www.cdcxhl.com"+src;    //绝对路径
            $(this).attr("src",url);
        }
    });
    window.onload=function(){
        document.oncontextmenu=function(){
            return false;
        }
    }
</script>