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
And to use is press simple
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