问题描述
就是用C#程序,将从淘宝搜到的图片和数据存到数据库,这个怎么做啊,做了半天用正则表达式只能显示出来图片,不会存到数据库
解决方案
解决方案二:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Net;usingSystem.Text.RegularExpressions;namespacesearch{publicpartialclassForm1:Form{WebClientclient=newWebClient();publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){listBoxLin.Items.Clear();listBoxImage.Items.Clear();pictureBox1.Image=null;webBrowser1.Url=newUri("about:blank");richTextBox1.Clear();stringurlString=textBoxUrl.Text.Trim();if(urlString.StartsWith("http://")==false){urlString="http://"+urlString;textBoxUrl.Text=urlString;}stringhttpSourse;try{Cursor.Current=Cursors.WaitCursor;WebClientwebClient=newWebClient();httpSourse=webClient.DownloadString(textBoxUrl.Text);richTextBox1.Text=httpSourse;webBrowser1.Url=newUri(textBoxUrl.Text);}catch(Exceptionerr){MessageBox.Show(err.Message);return;}finally{Cursor.Current=Cursors.Default;}stringregexHrefPattern=@"<as+hrefs*=s*""?([^"">])""?>(.+)</a>";RegexmyRegex=newRegex(regexHrefPattern,RegexOptions.IgnoreCase);MatchmyMatch=myRegex.Match(httpSourse);while(myMatch.Success==true){listBoxLin.Items.Add(myMatch.Groups[0].Value);myMatch=myMatch.NextMatch();}stringregexImgPattern=@"<img[^>]+(data-ks-lazyload)s*=s*""?([^"">]+)""?(?:[^>]+([^"">]+)""?)?";myRegex=newRegex(regexImgPattern,RegexOptions.IgnoreCase);myMatch=myRegex.Match(httpSourse);label7.Text="";while(myMatch.Success==true){listBoxImage.Items.Add(myMatch.Groups[2].Value);myMatch=myMatch.NextMatch();}}privatevoidlistBoxImage_Click(objectsender,EventArgse){strings=textBoxUrl.Text;intindex=s.LastIndexOf("/");if(index==-1){index=s.LastIndexOf("\");}stringurlpath=s.Substring(0,index+1);stringpath=listBoxImage.SelectedItem.ToString();stringpath1=path;if(path.StartsWith("http://")==false){path1=urlpath+path;}stringimageUrl=path1;try{pictureBox1.Image=Image.FromStream(client.OpenRead(imageUrl));}catch(Exceptionex){MessageBox.Show(ex.Message+"nn"+path1);}}}}
解决方案三:
怎么把查到的图片保存到根目录下???
解决方案四:
上面的代码也是按书上打的。。。