Octocat,看着喜欢就都下载下来了

看见github的octocat很喜欢,就用c#写了个程序统统download了,附上一个比较高效的下载程序,以及文末的图片压缩包。

用到了Jumony解析网页。

HttpClient client = new HttpClient();
var htmlSource = new JumonyParser().LoadDocument("https://octodex.github.com/").Find("a.preview-image > img");
Parallel.ForEach(htmlSource, async htmlElement =>
{
    var src = string.Format(@"https://octodex.github.com{0}", htmlElement.Attribute("data-src").Value());
    var filename = string.Format(@"F:\octocat\{0}", src.Substring(src.LastIndexOf('/') + 1));
    using (var stream = await client.GetStreamAsync(src))
    {
        using (var fileStream = new FileStream(filename, FileMode.CreateNew))
        {
            byte[] buffer = new byte[8192];
            int byteRead = -1;
            while ((byteRead = stream.Read(buffer, 0, 8192)) > 0)
            {
                fileStream.Write(buffer, 0, byteRead);
            }
        }
    }
    Console.WriteLine(filename);
});
Console.WriteLine("done!");

百度网盘 http://pan.baidu.com/s/1i3m3L6P

posted on 2015-10-03 17:00  Yosef Gao  阅读(614)  评论(0编辑  收藏  举报

导航