Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Created February 10, 2015 19:32
Show Gist options
  • Save AlbinoDrought/cc456aa8522699ce36ed to your computer and use it in GitHub Desktop.
Save AlbinoDrought/cc456aa8522699ce36ed to your computer and use it in GitHub Desktop.
Example C# Gargl output of yahoo template
using System;
using System.Net;
using System.IO;
public class YahooSearch
{
public string Autocomplete (string term)
{
string url = "http://sugg.search.yahoo.com/gossip-us-fp/" + "?output=yjsonp&nresults=10&version=&command=" + term + "&queryfirst=2";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
req.Method = "GET";
req.SetRawHeader("Accept", "*/*");
req.SetRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
req.SetRawHeader("Referer", "http://www.yahoo.com/");
req.SetRawHeader("Connection", "keep-alive");
req.SetRawHeader("Host", "sugg.search.yahoo.com");
req.SetRawHeader("Accept-Encoding", "gzip,deflate,sdch");
req.SetRawHeader("Accept-Language", "en-US,en;q=0.8");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();int responseCode = (int)resp.StatusCode;
Console.WriteLine("Sending 'GET' request to URL : " + url);
Console.WriteLine("Response Code : " + responseCode);
string response;using(StreamReader input = new StreamReader(resp.GetResponseStream())) {
response = input.ReadToEnd();
}
Console.WriteLine(response.ToString());
return response.ToString();
}
public string Search (string query)
{
string url = "http://search.yahoo.com/search" + "?p=" + query + "&ei=UTF-8&cop=mss&toggle=1&fr=yfp-t-900";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
req.Method = "GET";
req.SetRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
req.SetRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101 Safari/537.36");
req.SetRawHeader("Referer", "http://www.yahoo.com/");
req.SetRawHeader("Connection", "keep-alive");
req.SetRawHeader("Host", "search.yahoo.com");
req.SetRawHeader("Accept-Encoding", "gzip,deflate,sdch");
req.SetRawHeader("Accept-Language", "en-US,en;q=0.8");
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();int responseCode = (int)resp.StatusCode;
Console.WriteLine("Sending 'GET' request to URL : " + url);
Console.WriteLine("Response Code : " + responseCode);
string response;
using(StreamReader input = new StreamReader(resp.GetResponseStream())) {
response = input.ReadToEnd();
}
Console.WriteLine(response.ToString());
return response.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment