Welcome to Dream.In.Code
Become a C# Expert!

Join 150,413 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,019 people online right now. Registration is fast and FREE... Join Now!




Extracting Images from HTML

 
Reply to this topicStart new topic

Extracting Images from HTML

Yeoj
28 Mar, 2008 - 03:06 AM
Post #1

New D.I.C Head
*

Joined: 22 Nov, 2005
Posts: 28


My Contributions
I am trying to create an app that will extract all the results from a google image search consisting of keywords that the user defined. I got to the point where the user may enter their queries and the page will display in a web browser, but I really would like the images to be displayed only. This would be easy if the links remained the same, but obviously it varies from search to search. Therefore, i must download and/or display all images on the page, not including the google logo image (http://images.google.com/images/nav_logo3.png) How can i achieve this?

I would post what code i have now, but i really have no idea how to begin this concept. Any tips would be much appreciated.
User is offlineProfile CardPM
+Quote Post

zakary
RE: Extracting Images From HTML
28 Mar, 2008 - 04:58 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
so if you are using http://www.google.com to search in your code change that to http://images.google.com that should take you right to the images page
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Extracting Images From HTML
28 Mar, 2008 - 06:33 AM
Post #3

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You could also use Regular Expressions to find and parse all <img tags, something like


csharp

public string DisplayImage(string source)
{
string imgSource = string.Empty;
string pattern = @"<img[^>]*src="([^"]*)"[^>]*>@Usi";
RegEx check = New RegEx();
if(RegEx.IsMatch(source,pattern))
{
imgSrc = RexEx.Split(source,pattern);
return imgSrc;
}
}



That example returns just a single image, for multiple images you're going to want to loop through each match and add them to a string array (or Hashtable or ArrayList, etc) then return that

This post has been edited by PsychoCoder: 28 Mar, 2008 - 06:34 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 07:59PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month