asp.net插入数据时 出现问题
主要代码如下:privatevoidFindLink(stringhtml){this.TextBox3.Text="";List<string>hrefList=new...
主要代码 如下 :private void FindLink(string html)
{
this.TextBox3.Text="";
List<string> hrefList = new List<string>();//链接
List<string> nameList = new List<string>();//链接名称
string s = ConfigurationManager.ConnectionStrings["bishe"].ConnectionString;
SqlConnection conn = new SqlConnection(s);
conn.Open();
//string pattern = @"<a\s*href=(""|')(?<href>[\s\S.]*?)(""|').*?>\s*(?<name>[\s\S.]*?)</a>";
string pattern = @"<a\s*href=(""|')(?<href>(http:)[\s\S.]*?)(""|').*?>\s*(?<name>[\s\S.]*?)</a>";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
if (m.Success)
{
//加入集合数组
hrefList.Add(m.Groups["href"].Value);
nameList.Add(m.Groups["name"].Value);
this.TextBox3.Text += m.Groups["href"].Value + "|" + m.Groups["name"].Value + "\n";
string sql = "insert into [URL] values('" + m.Groups["href"].Value + "','" + m.Groups["name"].Value +"','" + i + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
i++;
}
}
} 展开
{
this.TextBox3.Text="";
List<string> hrefList = new List<string>();//链接
List<string> nameList = new List<string>();//链接名称
string s = ConfigurationManager.ConnectionStrings["bishe"].ConnectionString;
SqlConnection conn = new SqlConnection(s);
conn.Open();
//string pattern = @"<a\s*href=(""|')(?<href>[\s\S.]*?)(""|').*?>\s*(?<name>[\s\S.]*?)</a>";
string pattern = @"<a\s*href=(""|')(?<href>(http:)[\s\S.]*?)(""|').*?>\s*(?<name>[\s\S.]*?)</a>";
MatchCollection mc = Regex.Matches(html, pattern);
foreach (Match m in mc)
{
if (m.Success)
{
//加入集合数组
hrefList.Add(m.Groups["href"].Value);
nameList.Add(m.Groups["name"].Value);
this.TextBox3.Text += m.Groups["href"].Value + "|" + m.Groups["name"].Value + "\n";
string sql = "insert into [URL] values('" + m.Groups["href"].Value + "','" + m.Groups["name"].Value +"','" + i + "')";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
i++;
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询