控制台能得到图片的链接,手动粘贴复制能打开看见图片,但是用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();
求大佬指点一下出了什么问题。