Due to IT policy restrictions, I cannot use Selenium, try if this code can work for you.
static void Main(string[] args)
{
List<string> ImageList = GetAllImages();
using (WebClient client = new WebClient())
{
for (int i = 1; i < ImageList.Count; i++)
{
client.DownloadFile(new Uri(ImageList[i]), @"C:\Users\...\"+i+".jpg");
}
}
}
public static List<string> GetAllImages()
{
List<string> ImageList = new List<string>();
WebClient x = new WebClient();
string source = x.DownloadString(@"https://www.google.com.hk/search?q=wallpapers+pics&tbm=isch&ved=2ahUKEwizlL6W6sLxAhUE_4UKHS_YBDEQ2-cCegQIABAA&oq=wallpapers+pics&gs_lcp=CgNpbWcQAzICCAAyAggAMgIIADICCAAyAggAMgIIADICCAAyAggAMgIIADICCAA6BwgAELEDEEM6BAgAEENQ3I8FWJ6YBWDsnQVoAHAAeACAAasCiAHYCZIBAzItNZgBAKABAaoBC2d3cy13aXotaW1nwAEB&sclient=img&ei=bjXeYLOlJ4T-lwSvsJOIAw&bih=802&biw=1707");
HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
document.LoadHtml(source);
foreach (var link in document.DocumentNode.Descendants("img").Select(i => i.Attributes["src"]))
{
ImageList.Add(link.Value);
}
return ImageList;
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.