首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

急究竟是哪里出现了有关问题? C#

2011-12-12 
急急急,究竟是哪里出现了问题? C#usingSystemusingSystem.Collections.GenericusingSystem.TextusingSy

急急急,究竟是哪里出现了问题? C#
using   System;
using   System.Collections.Generic;
using   System.Text;
using   System.Text.RegularExpressions;
using   System.Data;
using   System.Data.SqlClient;
using   System.Net;
using   System.IO;
using   System.Web;


namespace   Notebook_PC_Channel
{
        class   Program
        {
                static   void   Main(string[]   args)
                {
                        string   strconnection= "Server=127.0.0.1;uid=sa;password=wxj;database=ztx; ";
                      //   string   strsql   =   "select   *   from   notebook_pc_brand   where   yes_image_url   is   not   null ";

                        string   strsql   =   "select   yes_image_url   from   notebook_pc_brand   where   yes_image_url   !=   ' ' ";
                        SqlConnection   sqlconnection2   =   new   SqlConnection(strconnection);
                        SqlCommand   sqlcommand2   =   new   SqlCommand(strsql,sqlconnection2);
                        SqlDataReader   sqlread2   =   null;
                        string   mystring= " ";
                        Regex   re   =   new   Regex(@ " <div   class= " "pro_img " "> [\s\S]*?href= " "(? <地址> [\s\S]*?) " "[\s\S]*?src= " "(? <图片> [\s\S]*?) " "[\s\S]*?   class= " "a_lan12b " "> (? <型号> [\s\S]*?) </a> [\s\S]*?   class= " "up_two " "> <a   href= " "(? <价格地址> [\s\S]*?) " "[\s\S]*?¥(? <价格> [\s\S]*?) </a> [\s\S]*?class= " "up_three " "> (? <日期> [\s\S]*?) </div> [\s\S]*? <div   class= " "price_brief " "> \n[\s\S]*?(? <描述> 笔记本[\s\S]*?) </div> [\s\S]*?class= " "info_cnt " "> · <a   href= " "(? <商家地址> [\s\S]*?) " "[\s\S]*? <span   class= " "lan12x " "> (? <商家数量> [\s\S]*?) </span> [\s\S]*? <div   class= " "info_cnt " "> · <a   href= " "(? <评论地址> [\s\S]*?) " "[\s\S]*?   class= " "lan12x " "> (? <评论数量> [\s\S]*?) </span> [\s\S]*?class= " "info_cnt " "> · <a   href= " "(? <新闻地址> [\s\S]*?) " "[\s\S]*? <span   class= " "lan12x " "> (? <新闻数量> [\s\S]*?) </span> [\s\S]*? <div   class= " "comp " "> [\s\S]*?href= " "(? <比较价格> [\s\S]*?) " "[\s\S]*? <table   class= " "offset_tab " "   [\s\S]*?this.page.value,(? <分页数量> [\s\S]*?), '(? <前缀> [\s\S]*?) ' ");
                   


                        WebClient   mywebclient   =   new   WebClient();
                        mywebclient.Credentials   =   CredentialCache.DefaultCredentials;
                        try
                        {
                                sqlconnection2.Open();
                                sqlread2   =   sqlcommand2.ExecuteReader();
                             
                                while   (sqlread2.Read())
                                {
                                       
                                                mystring   +=   sqlread2[ "yes_image_url "].ToString()   +   "\n ";
                                                byte[]   mybyte   =   mywebclient.DownloadData(sqlread2[ "yes_image_url "].ToString());
                                             
                                                string   my_byte_string   =   Encoding.Default.GetString(mybyte);
                                                MatchCollection   mc   =   re.Matches(my_byte_string);

                                                foreach   (Match   m   in   mc)
                                                {
                                                 

                                                        Console.WriteLine( "连接地址:     "   +   m.Groups[ "地址 "].ToString());


                                        }
                                 


                                   
                                }
                             
                             
                             
                        }
                        catch   (Exception   ex)
                        {
                                Console.WriteLine( "抓取数据出现错误 "+ex.ToString());
                        }
                        Console.ReadLine();
                }
        }
}


我的notebook_pc_brand表里面有24条数据,但是这个程序好像只走了我的数据表中的第一条数据。也就是只运行了一个url。

[解决办法]

热点排行