若图片平均大小为 1M,那么 4000 / (15 * 60) = 4.44 M/s 也就是你这少需要 30M 线路带宽,已经很快了 如果开宽还有富裕,是可以考虑用多线程的 你可以设一个待抓取图片的队列,每个线程只从队首取出图片 url,这样就不会重复了 如果抓取失败,还应将相应 url 重新入队
[quote=引用 30 楼 zhi_ai_yaya 的回复:] 我又回来了!!
[quote=引用 32 楼 sinat_25186077 的回复:] [quote=引用 30 楼 zhi_ai_yaya 的回复:] 我又回来了!!
我又回来了!!
我觉得异步会快些吧
[quote=引用 20 楼 sinat_25186077 的回复:] [quote=引用 17 楼 crystal_lz 的回复:] private Queue<string> m_que_url = new Queue<string>(); private void DownLoadCallBack() { string strUrl = string.Empty; WebClient web = new WebClient(); while (true) { lock (m_que_url) { if (m_que_url.Count == 0) break; strUrl = m_que_url.Dequeue(); } try { web.DownloadFile(strUrl, "yourfilename"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //set m_que_url int nThreadCount = 50; for (int i = 0; i < nThreadCount; i++) { new Thread(DownLoadCallBack) { IsBackground = true }.Start(); }
private Queue<string> m_que_url = new Queue<string>(); private void DownLoadCallBack() { string strUrl = string.Empty; WebClient web = new WebClient(); while (true) { lock (m_que_url) { if (m_que_url.Count == 0) break; strUrl = m_que_url.Dequeue(); } try { web.DownloadFile(strUrl, "yourfilename"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //set m_que_url int nThreadCount = 50; for (int i = 0; i < nThreadCount; i++) { new Thread(DownLoadCallBack) { IsBackground = true }.Start(); }
[quote=引用 17 楼 crystal_lz 的回复:] private Queue<string> m_que_url = new Queue<string>(); private void DownLoadCallBack() { string strUrl = string.Empty; WebClient web = new WebClient(); while (true) { lock (m_que_url) { if (m_que_url.Count == 0) break; strUrl = m_que_url.Dequeue(); } try { web.DownloadFile(strUrl, "yourfilename"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } //set m_que_url int nThreadCount = 50; for (int i = 0; i < nThreadCount; i++) { new Thread(DownLoadCallBack) { IsBackground = true }.Start(); }
先mark,节后我回来收取代码刚好有上百万张图片url要抓,虽然大部分不怎样,但有小部分是很给力的图片方便的话贴段代码,感谢楼主
110,502
社区成员
642,567
社区内容
加载中
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧