Click here to Skip to main content
15,885,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I get the first x results from a google images search into multiple pictureboxes in vb.net?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Mar-15 21:43pm    
Sounds like a pretty simple thing. What have you tried so far?
—SA
iProgramIt 16-Mar-15 21:49pm    
Well, I tried inserting a website image picture, then realized I wanted an integrated search & insert pic function.
Sergey Alexandrovich Kryukov 16-Mar-15 21:52pm    
Please see my answer.
—SA
iProgramIt 16-Mar-15 21:54pm    
Thank you
Sergey Alexandrovich Kryukov 16-Mar-15 21:56pm    
You are very welcome. Good luck, call again.
—SA

All you need is this: https://msdn.microsoft.com/en-us/library/system.net.httpwebrequest%28v=vs.110%29.aspx[^].

Basically, you first send HTTP request with search, receive the search results and parse it for image URLs, for each image, perform additional HTTP request to download each image. Load each image using Image.FromStream:
https://msdn.microsoft.com/en-us/library/93z9ee4x(v=vs.110).aspx[^].

Assign PictureBox.Image to each corresponding image: https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.image(v=vs.110).aspx[^].

All this is related to the techniques of Web scraping: http://en.wikipedia.org/wiki/Web_scraping[^].

See also my past answers:
get specific data from web page[^],
How to get the data from another site[^].

Depending on your design of the form representing found images, PictureBox may or may not be the most suitable. You may want to choose direct rendering of images on some control using overridden Control.OnPaint or handling Control.Paint event.

—SA
 
Share this answer
 
Comments
iProgramIt 16-Mar-15 21:57pm    
Sorry for the noobiness, but how would I do a search and recieve it?
Sergey Alexandrovich Kryukov 16-Mar-15 22:08pm    
No problem, this is a natural question.
It will request little experimenting. You need to observe what happens when you search using a regular Web browser and, basically, do the same thing programmatically.

By the way, I sometimes use my secret weapon: HttpFox add-on for Mozilla browsers. You switch the capture on and spy on HTTP requests/responses passed through the browser. Google Chrome has a similar plug-in tool you would need to install. If I'm not much mistaken, all the search request is passed through the URL, so all you need is to learn this URL query string. Try to find it in Google documentation.

Google used to have search API, which is currently deprecated; so please see what's on the present-day Google API's Client Library. Please see:
http://en.wikipedia.org/wiki/Google_APIs,
https://developers.google.com/api-client-library/dotnet/get_started.

But even without all that, you can scrape the regular search, imitating all the step the regular Google user uses for the search.

—SA
iProgramIt 16-Mar-15 22:39pm    
Okay, so searching is all right now. Can you please give me a code snippet as to list all the image url's on the webpage please? Thank you.
Sergey Alexandrovich Kryukov 16-Mar-15 22:54pm    
I'm afraid that would need too much time. You can use the parser I referenced in my past answer, or just use the Regex search. Regex could be good enough if you only need to search for image URLs; they all have characteristic URLs easy to recognize http://.... *.jpg, ...*.png, something like that; you may also need to include "<img..." in search.

Start with doing some manual search and look at the page source on a results page, it will give you an idea on what to look for. This is just some regular R&D work, not something which need some special expert's advice...

—SA
"But even without all that, you can scrape the regular search, imitating all the step the regular Google user uses for the search."

CUrrent problem is that in C# you cannot imitate the sdch compression (not supported so far by Webrequest, Webclient, HttpClient), and google will not deliver you the raw results except you use a sdch enable software like chrome webbrowser!

You need to provide in your header "Avail-Dictionary" and the decompress the data...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900