熬了半夜,终于找到了如何在百度图库中得到需要图片的下载链接的方法了,现整理如下
private IList<string> GetPictureDownPath(string name)
{
IList<string> path = new List<string>();
string strHTML = "";
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());
}
return path;
}
由于发链接限制,需要去掉代码中第六行中的‘啊”字。
该方法参数为输入的欲搜索的图片的名字,如张学友,韩雪等。返回结果为包含不定个下载链接的IList<string> 。
注:转载请注明