How to grab a picture from a webpage (vb.net)

Zoino
10 years ago

0

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?

10replies
5voices
228views
2images
Pete Maynard [Osaka]
10 years ago

0

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

Zoino
10 years ago | edited 10 years ago

0

There is no file extension visible in the URL. Here is the HTML for the image. I need something that would identify the image over the other images/icons on the page.

xxxxx

Pawda [Memoria]
10 years ago

0

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.

Zoino
10 years ago

0

Im not following your logic, maybe i didn’t explain it clearly. Get me on the IRC

[deleted user]
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?

Zoino
10 years ago

0

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.

[deleted user]
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.

Cyan Wind [freewind1012]
10 years ago | edited 10 years ago

0

@Zoino: When viewing source code of a web page, there are always markup stuff in HTML like:
```

image1.jpg

image1.jpg
```

@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…

Zoino
10 years ago | edited 10 years ago

0

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.

Pawda [Memoria]
10 years ago

0

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.)

You must be logged in to reply to this discussion. Login
1 of 11

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss