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
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站