How to grab a picture from a webpage (vb.net)
How would I grab a specific image from a specific webpage, and i mean the image source. i.e. a webpages URL is inputted into a text box and then a result of a specific image (selected by me) on that webpage appears in a picture box. For instance i type in “https://www.hackthis.co.uk” into the text box and a result of the hack this logo is returned into the picture box. How would I get a specific image to display?
I guess if I were to do it, I’d write it in something like Python, as Python has lots of libraries which can help you do it. I guess it would be broken down into these steps:
1 Open URL and examine the contents of the HTML
2 Look for any URLs which end in png/jpg etc
3 Download all images/display the images
Folding@Home Stats | Official Thread | Team Number: 223679
You don’t have to know the extension, .NET already manage this for you.
All you have to do is as Osaka said:
1) grab html content form url (HttpClient, WebRequest, WebClient, Socket, whatever…)
2) use an html parser (htmlagilitypack) and select images node (//img) get the src attribute.
3) download image and do something with.
The things is filename has no importance as you can pass a stream of your file into the .NET methods, the file format is actually defined in the image binary.
10 years ago
0
Zoino, if I am getting it right you want something like the google image search correct. If we do a google image search for https://www.hackthis.co.uk it show a lot of images pertaining to hackthis.co.uk but in your case you want only one image to show up. Am I correct so far?
Yes partly correct, except one thing. which is quite hard to explain. Say for instance you wanted your program to return a specific image on the YouTube homepage. For example the thumbnail image of the first video on the ‘suggestions’ panel, however that image will change very often. The position of the thumbnail on the page doesn’t change, just the image. I need a way to pick out that certain image even when it is constantly changing.
10 years ago
0
Zoino, I don’t know if that is possible. It might be but its way beyond my knowledge. You might need to get some suggestion from experts on this website.
@Zoino: When viewing source code of a web page, there are always markup stuff in HTML like:
```
```
@Memoria ’s method is a good one:
[list]
[] Retrieve content from a web page by cURL or Wget.
[] Manipulate the HTML by HTML DOM Parser.
[*] Download the image.
[/list]
That’s what I did by using open source library. But in VB.NET, not sure…
The image source changes, i need a ‘constant’ that will define the image. I have found out that the image i am looking for is the only image on the page that is 320x320 pixels. Is there a way to pick out an image of certain size?
I have found this, but its not clear at all and lots of the code is broken.
Like I said, you can select the nodes you want.
Htmlagilitypack for .net allow you to select an html node via xpath.
You don’t need care what’s in the src attribute before parsing the dom since that’s the thing you wanna get.
To answer you, yes you could sort image by sizes and keep only the 320/320 ones but depending how the dom is made you might need to download them first if you want to check their sizes…
(I’m on irc if needed.)