下载百度上的图片C#——输入名字就可以下载
2016-03-30 15:23
162 查看
using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace crawel_picture {
class Program {
static void Main(string[] args)
{
IList<string> path = new List<string>();
string strHTML = "";
string name = "水杯";
int num1 = 2;
int num = 2000000;
WebClient myWebClient = new WebClient();
Stream myStream = myWebClient.OpenRead("http://image.baidu.com/i?tn=baiduimage&ct=201326592&lm=-1&cl=2&nc=1&word=" + name + "&ie=utf-8&ie=utf-8"); StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));
strHTML = sr.ReadToEnd();
myStream.Close();
MatchCollection lrc1 = Regex.Matches(strHTML, @"[objURL]{6}.:.http://.*");
foreach (Match s in lrc1)
{
path.Add(Regex.Split(s.ToString(), "\"")[2].ToString());
}
for (int i = 0; i < path.Count;i++ )
{
num++;
myWebClient.DownloadFile(path[i], @"E:\爬虫图片\" + num1 + "\\" + num.ToString() + ".jpg");
}
}
}
}
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Net;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace crawel_picture {
class Program {
static void Main(string[] args)
{
IList<string> path = new List<string>();
string strHTML = "";
string name = "水杯";
int num1 = 2;
int num = 2000000;
WebClient myWebClient = new WebClient();
Stream myStream = myWebClient.OpenRead("http://image.baidu.com/i?tn=baiduimage&ct=201326592&lm=-1&cl=2&nc=1&word=" + name + "&ie=utf-8&ie=utf-8"); StreamReader sr = new StreamReader(myStream, System.Text.Encoding.GetEncoding("utf-8"));
strHTML = sr.ReadToEnd();
myStream.Close();
MatchCollection lrc1 = Regex.Matches(strHTML, @"[objURL]{6}.:.http://.*");
foreach (Match s in lrc1)
{
path.Add(Regex.Split(s.ToString(), "\"")[2].ToString());
}
for (int i = 0; i < path.Count;i++ )
{
num++;
myWebClient.DownloadFile(path[i], @"E:\爬虫图片\" + num1 + "\\" + num.ToString() + ".jpg");
}
}
}
}
相关文章推荐
- C# 调用Excel 出现服务器出现意外情况. (异常来自 HRESULT:0x80010105 (RPC_E_SERVERFAULT)
- C#委托的介绍(delegate、Action、Func、predicate)
- C# Action<T> 委托
- C# 发送邮件方法2
- c#主窗体向子窗体上的报表传参数
- C#高性能大容量SOCKET并发(一):IOCP完成端口例子介绍(转)
- Gmap.net百度地图开发
- C# 发送邮件方法
- 详解C#利用DataTable导出Excel
- 关于C#的Equals和Contains方法
- C# 去除字符串首尾字符或字符串
- C#中的强制类型转换与as转换的区别
- C#序列化及反序列化:类实例和string类型之间转换
- C#中的委托(Delegate)和事件(Event)
- C#中的泛型
- C#中的数组作为参数传递所引发的问题
- C# 委托 多线程
- c# 多态
- C#dynamic关键字(1)
- C# 访问修饰符 public、private、protected、internal