取出来放在电脑里,然后给后面的程序调用,C#语言的,用什么方式

解决方案 »

  1.   

    先将网页全部内容取出来//取网页内容:方法1
                WebBrowser webBrowser = new WebBrowser();            webBrowser.Navigate("网址");            string htmlContex = webBrowser.DocumentText;
    方法2:参考
            public static string GetImgUrl(string htmlContent)
            {            string imageUrl = string.Empty;            //string sPattern = @"^<img/s+[^>]*>";            Regex regex = new Regex(@"<img/s+[^>]*/s*src/s*=/s*([']?)(?<url>/S+)'?[^>]*>",                RegexOptions.Compiled);            Match match = regex.Match(htmlContent.ToLower());            if (match.Success)                imageUrl = match.Result("${url}");            return imageUrl;        }
      

  2.   

    private void button1_Click(object sender, EventArgs e)
            { 
    string httpSourse;
    string regexImgPattern = @"<img[^>]+(data-ks-lazyload)\s*=\s*""?([^"">]+)""?(?:[^>]+([^"">]+)""?)?";
                myRegex = new Regex(regexImgPattern, RegexOptions.IgnoreCase);
                myMatch = myRegex.Match(httpSourse);
                label7.Text = "";
                while (myMatch.Success == true)
                {
                    listBoxImage.Items.Add(myMatch.Groups[2].Value);
                     myMatch = myMatch.NextMatch();
                }}
      private void listBoxImage_Click(object sender, EventArgs e)
            {
                string s = textBoxUrl.Text;
                int index = s.LastIndexOf("/");
                if (index == -1)
                {
                    index = s.LastIndexOf("\\");
                }
                string urlpath = s.Substring(0, index + 1);
                string path = listBoxImage.SelectedItem.ToString();
                string path1 = path;
                if (path.StartsWith("http://") == false)
                {
                    path1 = urlpath + path;
                }
                string imageUrl = path1;
                try
                {
                    pictureBox1.Image = Image.FromStream(client.OpenRead(imageUrl));
                    
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\n\n" + path1);
                }
            }
      

  3.   

    根据Url下载文件   void myTest()
            {
                Stream reader = null;
                FileStream stream = null;
                try
                {
                    //文件地址
                    WebRequest request = WebRequest.Create(@"http://pic.nipic.com/2007-12-10/20071210224154962_2.jpg");                WebResponse response = request.GetResponse();
                    reader = response.GetResponseStream();                stream = File.Open("D:myPic.png", FileMode.OpenOrCreate, FileAccess.Write);                byte[] buf = new byte[512];
                    int cnt;
                    while ((cnt = reader.Read(buf, 0, buf.Length)) > 0)
                    {
                        stream.Write(buf, 0, cnt);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                        stream.Close();
                    }
                }
            }