Yahoo! search interface: Difference between revisions

replaced google -> yahoo
No edit summary
(replaced google -> yahoo)
Line 15:
using System.Collections.Generic;
using System.Linq;
 
class TestSearchYahooSearch {
private string query;
private string content;
private int page = 1;
 
public GoogleSearchYahooSearch(string query) {
this.query = query;
this.content = new WebClient().DownloadString("http://www.test.com/search?q=" + query);
}
 
public TestSearchYahooSearch(string query, int page) {
this.query = query;
this.page = page;
this.content = new WebClient().DownloadString(String.Format("http://www.test.com/search?q={0}&start={1}", query, (this.page - 1) * 10));
}
 
public int Page {
get {
Line 37:
}
}
 
public int Length {
get {
Line 44:
}
}
 
public GoogleResultYahooResult[] Results {
get {
ArrayList results = new ArrayList();
 
foreach (Match e in new Regex("<li class=g><h3 class=r><a href=\"(.+?)\".+?>(.+?)</a></h3><div class=\"s\">(.+?)<cite>").Matches(this.content)) {
string rurl = e.Groups[1].Value;
 
string rtitle = e.Groups[2].Value.
Replace("<em>", "").Replace("</em>", "").Replace(" <b>...</b>","");
string rcontent = e.Groups[3].Value.
Replace("<em>", "").Replace("</em>", "").Replace(" <b>...</b>", "");
 
Console.WriteLine(rurl);
results.Add(new TestResultYahooResult(rurl, rtitle, rcontent));
}
return (TestResultYahooResult[])results.ToArray(typeof(TestResultYahooResult));
}
}
 
public GoogleSearch NextPage() {
return new TestSearchYahooSearch(this.query, this.page + 1);
}
 
public GoogleSearch GetPage(int page) {
return new TestSearchYahooSearch(this.query, page);
}
}
 
class TestResultYahooResult {
public string URL { get; set; }
public string Title { get; set; }
public string Content { get; set; }
 
public TestResultYahooResult(string url, string title, string content) {
this.URL = url;
this.Title = title;
Anonymous user