取出来放在电脑里,然后给后面的程序调用,C#语言的,用什么方式
解决方案 »
- C#两个窗体间传值的问题,求你们给我看看啊,求各位高手指点一二啊
- c#输出
- ListView 放了背景图片,没有数据的时候能看到背景,有数据怎么就看不到背景了呢?
- 请问用Socket获取一个验证码输出网页,怎么把图片部分弄出来?
- 在vs2005中修改app.config的怪事?
- vs2005windows程序打包
- 初学者,一段找来的操作EXCEL的代码,搞不懂MyWorkBooks.Add (Missing.Value) 是什么意思?
- 求C#的屏幕取词的例子!
- 怎么样让windows form的一列cell变成一个下拉菜单呢?
- 关于添加引用的问题
- Fastreport.net webreport控件的一个问题 急求
- C# 自定义button请教
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; }
{
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);
}
}
{
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();
}
}
}