xgq_Star 2020-04-27 14:10 采纳率: 50%
浏览 314
已采纳

请问为什么无法下载这个链接的图片

控制台能得到图片的链接,手动粘贴复制能打开看见图片,但是用webClient下载时没反应,还提示网络路径错误,求解决,这问题困扰了我一天了。

 string url = "http://jandan.net/ooxx/MjAyMDA0MjctMjAy#comments";
 //           string path=@"D:\Picture";
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.CreateHttp(url);
            webRequest.Method = "GET";
            webRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) ";
            var webResponse = webRequest.GetResponse();
            StreamReader streamReader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8);
            string str = streamReader.ReadToEnd();
            streamReader.Close();
            if (string.IsNullOrEmpty(str))
            {
                Console.WriteLine("————————-错误—————————");
                Console.ReadKey();
            }
            Regex regex = new Regex("<img.*?src=['|\"](?<Go>(.*?(?:\\.(?:png|jpg))))['|\"]");
            MatchCollection match = regex.Matches(str);
            WebClient client = new WebClient();
            try
            {
                foreach (Match match1 in match)
                {
                    string src = match1.Groups["Go"].Value;
     //               client.DownloadString(src);
                    Console.WriteLine("\n正在爬取———————" + "|" +src);                 
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("-------------" + ex);
            }
            Console.ReadKey();

求大佬指点一下出了什么问题。

  • 写回答

1条回答 默认 最新

  • yangxf啦啦啦 2020-04-27 14:54
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算