I am trying to download about 250 images from wikipedia with a c# .net console application. After downloading 3 I get this error.
System.Net.WebException: 'The remote server returned an error: (403) Forbidden. Please comply with the User-Agent policy: https://meta.wikimedia.org/wiki/User-Agent_policy. '
I have read their User-Agent_policy page and added a user agent that complies with what they say. (to the best of my ability, I'm not a web-dev)
They say, make it descriptive, include the word bot if its a bot, include contact details in parentheses, all of which I have done.
I am also waiting 5 seconds in between each image.. I just really really dont wanna download them by hand in my browser.
static void DownloadImages()
{
var files = Directory.GetFiles(@"C:\projects\CarnivoraData", "*", SearchOption.AllDirectories);
var client = new WebClient();
client.Headers.Add("User-Agent", "bot by <My Name> (<My email address>) I am downloading an image of each carnivoran once (less than 300 images) for educational purposes");
foreach (var path in files)
{
//Console.WriteLine(path);
//Console.WriteLine(File.ReadAllText(path));
AnimalData data = JsonSerializer.Deserialize<AnimalData>(File.ReadAllText(path));
client.DownloadFile("https:" + data.Imageurl,@"C:\projects\CarnivoraImages\"+ data.Name +Path.GetExtension(data.Imageurl));
System.Threading.Thread.Sleep(5000);
}
}
Any suggestions?