高手进来帮忙,新手进来学习!
string strconnection = "server=localhost;uid=sa;password=wxj;database=notebook;";
SqlConnection thisconnection = new SqlConnection(strconnection);
thisconnection.Open();
SqlCommand thiscommand = new SqlCommand("select brand,grabfrom from brand", thisconnection);
SqlDataReader thisread = thiscommand.ExecuteReader();
WebClient mywebclient = new WebClient();
mywebclient.Credentials = CredentialCache.DefaultCredentials;
int number = 0;
SqlCommand sqlcommand_successful = null;
string brand = "";
string grab_test= "";
while (thisread.Read())
{
brand += thisread["brand"].ToString();
grab_test += thisread["grabfrom"].ToString();
number++;
Console.WriteLine("这是中关村手机的第" + number + "品牌!" + " " +brand + "\n\n");
byte[] mybyte = mywebclient.DownloadData(grab_test);
string mystring = Encoding.Default.GetString(mybyte);
Regex re = new Regex(@"条,(?<page>[\s\S]*?)\s页");
MatchCollection mc = re.Matches(mystring);
int testabc = 0;
testabc++;
int testint = 0;
foreach (Match m in mc)
{
string test = m.Groups["page"].ToString();
int i = int.Parse(test);
for (int ztx = 1; ztx <= i; ztx++)
{
WebClient webclient2008 = new WebClient();
webclient2008.Credentials = CredentialCache.DefaultCredentials;
//thisread["grabfrom"].ToString().Replace("1", "3")
byte[] byte2008 = webclient2008.DownloadData(grab_test.Replace("_1.html", "_" + ztx.ToString() + ".html"));
string string2008 = Encoding.Default.GetString(byte2008);
Regex re2 = new Regex(@"<div class=""pro_img"">[\s\S]*?href=""(?<grab1>[\s\S]*?)""[\s\S]*?src=""(?<small_image>[\s\S]*?)""");
MatchCollection mc2 = re2.Matches(string2008);
foreach (Match m2 in mc2)
{
// Console.WriteLine(testabc + m2.Groups["grab1"].ToString() + m2.Groups["small_image"].ToString());
// string abc = m2.Groups["grab1"].ToString();
// Console.WriteLine(abc);
WebClient webclient_end = new WebClient();
webclient_end.Credentials = CredentialCache.DefaultCredentials;
byte[] end_byte = webclient_end.DownloadData(m2.Groups["grab1"].ToString());
string end_string = Encoding.Default.GetString(end_byte);
Regex regex_end = new Regex(@"id=""td_param"">[\s\S]*?href=""(?<grab2>[\s\S]*?)""");
&