I want to download first 10 images from the given Url stated in the following code of google images.. I have tried soo much ways but can't be able to download images because i got the wrong lengthy urls which seems to be junk data.
Here is my code as i am using C#,
var driver = new ChromeDriver();
// These are commented three ways to select the list of images
//IList<IWebElement> Imghref = driver.FindElements(By.XPath("//img[@jsname]"));
//IList<IWebElement> Imghref = driver.FindElements(By.ClassName("rg_i"));
//IList<IWebElement> Imghref = driver.FindElements(By.TagName("img"));
IList<IWebElement> Imghref = driver.FindElements(By.ClassName("rg_i"));
//BcuVif - n3VNCb --- ClassNames which i have observed
foreach (IWebElement eachLink in Imghref)
{
eachLink.Click();
IWebElement Images = driver.FindElement(By.TagName("img"));
//Console.WriteLine(Images.GetAttribute("class"));
String ImageUrl = Images.GetAttribute("src");
string ImageName = Images.GetAttribute("alt");
Console.WriteLine("Image URL : " + ImageUrl);
WebClient downloader = new WebClient();
downloader.DownloadFile(ImageUrl, "D:\\VisualStudio Workspace\\Download-Images\\images\\" + ImageName + ".jpg");
}
Kindly any possible fix .. this will be very much helpful for me.