Hi @JohnHenderson1963 ,
Do you want to collect pictures on this page?
https://www.google.com.hk/search?q=TurnYourLoveAround-GeorgeBenson&newwindow=1&safe=strict&source=lnms&tbm=isch&sa=X&ved=2ahUKEwjh-MKDksPwAhVTcCsKHU8jDQEQ_AUoAXoECAEQAw&biw=1600&bih=789
It seems that you cannot collect images on https://www.google.com/search?q=TurnYourLoveAround-GeorgeBenson
how to grab all images from webpage
Hi There,
I wonder if someone can help. First of all this relates to the following link, https://social.msdn.microsoft.com/Forums/en-US/97f32ddf-6bdf-4b3a-a23b-f245434109fb/how-to-grab-all-images-from-webpage?forum=vbgeneral.
The code that I have tried to use was the very last example at the bottom of the page. The issue I have appears at this line of code
img.Save(e.Argument(0) & "\img" & i & ".png")
with the error of "Object reference not set to an instance of an object"
Im not sure as to why I am getting this error. I am using VB 2019 latest community version. Any assistance would be appreciated.
Thank you.
-
Xingyu Zhao-MSFT 5,356 Reputation points
2021-05-12T02:57:51.817+00:00
2 additional answers
Sort by: Most helpful
-
Viorel 113.7K Reputation points
2021-05-07T16:11:42.977+00:00 Maybe try this modification:
If img IsNot Nothing Then img.Save(e.Argument(0) & "\img" & i & ".png")
and clarify why some of ‘IMAGES(i) = Image.FromStream(_WebStream)’ probably fail.
-
Xingyu Zhao-MSFT 5,356 Reputation points
2021-05-10T08:16:05.637+00:00 Hi @JohnHenderson1963 ,
You can consider using WebBrowser control to download all images.
For example:Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click WebBrowser1.Navigate("your url") End Sub Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted Dim browser = CType(sender, WebBrowser) Dim client = New WebClient() For Each img In browser.Document.Images Dim image = TryCast(img, HtmlElement) Dim src = image.GetAttribute("src").TrimEnd("/"c) If Not Uri.IsWellFormedUriString(src, UriKind.Absolute) Then src = String.Concat(browser.Document.Url.AbsoluteUri, "/", src) End If Dim filename = New String(src.Skip(src.LastIndexOf("/"c) + 1).ToArray()) If filename.EndsWith(".png") Or filename.EndsWith(".jpg") Then File.WriteAllBytes(filename, client.DownloadData(src)) End If Next End Sub
Best Regards,
Xingyu Zhao
*
If the answer 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.