[C#] Google URL Image Searching (Good to find Fakes)

Toyz
by Toyz · 3 posts
12 years ago in .Net (C#, VB, etc)
Posted 12 years ago · Author
Well I haven't designed a main page to handle the posting to it yet, but anyone with a brain of a pea can do it :)

Code
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Net;

namespace Toyz_Portfoilo.sBin
{
 public class SBIHelper
    {
        public static string SearchByImage(string URL)
        {
            HttpWebRequest request = WebRequest.Create(String.Format("http://www.google.com/searchbyimage?hl=en&site=search&image_url={0}", URL)) as HttpWebRequest;
            StringBuilder sb = new StringBuilder();
            string ImageName;
            byte[] buf = new byte[8192];

            request.Method = "GET";
            request.ProtocolVersion = HttpVersion.Version11;
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; rv:5.0) Gecko/20100101 Firefox/5.0";

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            var stream = response.GetResponseStream();

            string tempString = null;
            int count = 0;

            do
            {
                count = stream.Read(buf, 0, buf.Length);
                if (count != 0)
                {
                    tempString = Encoding.ASCII.GetString(buf, 0, count);
                    sb.Append(tempString);
                }
            }
            while (count > 0);

            string re1 = "(;)";
            string re2 = "(q)";
            string re3 = "(=)";
            string re4 = "((?:[a-z][a-z]+))";
            string re5 = ".*?";
            string re6 = "(&)";

            Regex r = new Regex(re1 + re2 + re3 + re4 + re5 + re6, RegexOptions.IgnoreCase | RegexOptions.Singleline);

            Match match = r.Match(sb.ToString());
            if (match.Success)
                ImageName = match.ToString().Remove(0, 3).TrimEnd('&').Replace("%20", " ");
            else
                ImageName = null;
                       
            return ImageName;
        }
    }
}


And to use is press simple

Code
public void main()
{
 console.writeLine(SBIHelper.SearchByImage({image url}));
}
Posted 12 years ago
My brain must be smaller than a pea. Mostly I am not as familiar with C# so that last piece of code stumps me as to where it's supposed to be put and called from.
Posted 12 years ago
Ð▪ℳ wrote:
My brain must be smaller than a pea. Mostly I am not as familiar with C# so that last piece of code stumps me as to where it's supposed to be put and called from.


The last line is just the main class. (the root of her code which calls up everything else)
All it does is send the image url to the SBIHelper helper class's SearchByImage function. (it passes the image's web address to the rest of her code to work with)
Then it writes the data to the console's output stream. (it write the output to the screen)

Oh, and your brain is not smaller than a pea.
If it was, you would not be my right hand man.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT