当前位置:编程学习 > asp >>

ASP.NET采集例子 一个小的网页爬虫


[原创]ASP.NET采集例子 百度搜索K8机器人 抓取标题和链接 改下网址和正则 可以随便抓指定站
或者加个多线程 再加上相关漏洞测试 就可以写个自动入侵网站的程序 下面仅仅是简单的例子

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using System.Net;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
   
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string htmlcode = GetHTML("http://www.baidu.com/s?wd=K8%BB%FA%C6%F7%C8%CB");//K8机器人
      
        Regex reg= new Regex("<table cellpadding=\"0\".*href=\"(?<k8url>.+).*target=\"_blank\">(?<k8title>.+)"); 

        MatchCollection ms = reg.Matches(htmlcode); 
        foreach (Match m in ms)
        {
            //this.Response.Write(m.Groups["k8url"]+" " + m.Groups["k8title"] + "<br>");  
            this.Response.Write("<a href=\"" + m.Groups["k8url"] + "\">" + m.Groups["k8title"] + "</a><br>");
        }
    }

    public string GetHTML(string url)
    {
        WebClient web = new WebClient();
        byte[] buffer = web.DownloadData(url);
        return Encoding.Default.GetString(buffer);
    }
}
补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,