public void Imagesaver(string url)
{
string result = Filename(url);
string SourceCode = worker.GetSourceCode(url);
List<string> names1 = new List<string>();
MatchCollection data2 = Regex.Matches(SourceCode, "(src=\"|src=\\/\")([^>]*?jpg|png|gif)", RegexOptions.Singleline);
string name = string.Empty;
foreach (Match m in data2)
{
name = m.Groups[2].Value;
if (name.Contains("http"))
{
names1.Add(name);
}
else
{
names1.Add(url+name);
}
}
WebClient client = new WebClient();
int i = 0;
foreach (string name2 in names1)
{
Uri imageurl = new Uri(name2);
try
{
client.DownloadFileAsync(imageurl, (@"C:\Users\Ramazan BIYIK\Desktop\HTML içerik\" + result+"\\" + i + ".jpg"));
i++;
}
catch(Exception ex)
{
continue;
}
}
}
I have a code block that saves .jpg
, .png
and .gif
extension files from source code in a website to local. But when I tried in debug and non-debug mode, it showed me different results.
For example in a web site there are 40 files with a .jpg
extension. In debug mode, I can download them, all but at runtime, I can download only 6 files.
I searched that problem but all answers are about numbers and I am not dealing with number (I suppose). Please help and sorry for my bad English.