public List<Article> MakeList(string[] searchCriteria) { List<Article> articles = new List<Article>(); int start = 0; foreach (string s in searchCriteria) { do { string url = string.Format(BaseUrl, s, Variables.URL, NoOfResultsPerRequest, start); using (XmlTextReader reader = new XmlTextReader(new StringReader(Tools.GetHTML(url)))) { while (reader.Read()) { if (reader.Name.Equals("Message")) { if (string.Compare(reader.ToString(), "limit exceeded", true) == 0) Tools.MessageBox("Query limit for Yahoo Exceeded. Please try again later"); return articles; } if (reader.Name.Equals("ResultSet")) { reader.MoveToAttribute("totalResultsAvailable"); if (!string.IsNullOrEmpty(reader.Value) && int.Parse(reader.Value) > TotalResults) start += NoOfResultsPerRequest; } if (reader.Name.Equals("ClickUrl")) { string title = Tools.GetTitleFromURL(reader.ReadString()); if (!string.IsNullOrEmpty(title)) articles.Add(new Article(title)); } } } } while (articles.Count < TotalResults); } return articles; }
public List<Article> MakeList(string[] searchCriteria) { List<Article> articles = new List<Article>(); int start = 1; foreach (string s in searchCriteria) { string url = string.Format(baseUrl, s, noResults, start); int resultsReturned = 0, totalResults = 0; do { using (XmlTextReader reader = new XmlTextReader(new StringReader(Tools.GetHTML(url)))) { while (reader.Read()) { if (reader.Name.Equals("Message")) { if (string.Compare(reader.ToString(), "limit exceeded", true) == 0) { Tools.MessageBox("Query limit for Yahoo Exceeded. Please try again later"); return articles; } } if (reader.Name.Equals("ResultSet")) { reader.MoveToAttribute("totalResultsAvailable"); string val = reader.Value; if (!string.IsNullOrEmpty(val)) totalResults = int.Parse(val); reader.MoveToAttribute("totalResultsReturned"); val = reader.Value; if (!string.IsNullOrEmpty(val)) resultsReturned = int.Parse(val); } if (reader.Name.Equals("DisplayUrl")) { string title = Tools.GetTitleFromURL("http://" + reader.ReadString()); if (!string.IsNullOrEmpty(title)) articles.Add(new Article(title)); } } } if (resultsReturned < 100) break; if ((articles.Count < totalResults) && (articles.Count <= 900)) start += noResults; else break; url = string.Format(baseUrl, s, noResults, start); } while (true); } return articles; }