[Original] ASP. NET collection examples Baidu search K8 robots capture titles and links change URLs and regular expressions can randomly capture specified sites
Or add a multi-thread program and related vulnerability tests to write a program that automatically invades the website. The following is a simple example.
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 button#click (object sender, EventArgs e)
{
String htmlcode = GetHTML ("http://www.baidu.com/s? Wd = K8 % BB % FA % C6 % F7 % C8 % CB "); // K8 Robot
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 );
}
}