public void GetCars() { var carNodes = doc.DocumentNode.SelectNodes("//tr[@class='search_vehicle_basic_row search_name_cell']"); if (carNodes != null) { foreach (var carNode in carNodes) { Dictionary <string, string> carProperties = new Dictionary <string, string>(); carProperties.Add("Lane", ""); carProperties.Add("Run", ""); carProperties.Add("Year", ScrapeYear(carNode)); carProperties.Add("MakeModel", ScrapeMakeModel(carNode)); carProperties.Add("EngineTransmission", ""); carProperties.Add("Odometer", ScrapeOdometer(carNode)); carProperties.Add("Color1", ScrapeColor1(carNode)); carProperties.Add("Color2", ""); carProperties.Add("Vin", ScrapeVin(carNode)); carProperties.Add("Bin", ""); carProperties.Add("Bid", ""); DecodeThisScraper decodeThisScraper = new DecodeThisScraper(); DecodeThisResult decodeThisResult = decodeThisScraper.GetResult(carProperties["Vin"]); carProperties.Add("DecodeThisYearMakeModel", decodeThisResult.YearMakeModel); CarInfoScraped(carProperties); } } }
public void GetCars() { using (StringReader reader = new StringReader(doc.DocumentNode.SelectSingleNode("//pre").InnerHtml)) { string line = string.Empty; do { line = reader.ReadLine(); if (line != null) { if (line.Contains("pre_inv_ps-vdp")) { Dictionary <string, string> carProperties = new Dictionary <string, string>(); Match match = Regex.Match(line, @"<a.*?>(.*?)</a>", RegexOptions.IgnoreCase); string matchValue = match.Value; string makeModel = Regex.Replace(matchValue, @"</?a.*?>", ""); line = line.Replace(matchValue, ""); string[] carPropertyArray = line.Trim().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); carProperties.Add("Lane", carPropertyArray[0]); carProperties.Add("Run", carPropertyArray[1]); carProperties.Add("Year", carPropertyArray[2]); carProperties.Add("MakeModel", makeModel); carProperties.Add("EngineTransmission", carPropertyArray[3]); carProperties.Add("Odometer", carPropertyArray[4]); carProperties.Add("Color1", carPropertyArray[5]); carProperties.Add("Color2", ""); carProperties.Add("Vin", carPropertyArray[6]); carProperties.Add("Bin", ""); carProperties.Add("Bid", ""); DecodeThisScraper decodeThisScraper = new DecodeThisScraper(); DecodeThisResult decodeThisResult = decodeThisScraper.GetResult(carProperties["Vin"]); carProperties.Add("DecodeThisYearMakeModel", decodeThisResult.YearMakeModel); CarInfoScraped(carProperties); } } } while (line != null); } }
public DecodeThisResult GetResult(string vin) { if (HtmlNode.ElementsFlags.ContainsKey("option")) { HtmlNode.ElementsFlags["option"] = HtmlElementFlag.Closed; } else { HtmlNode.ElementsFlags.Add("option", HtmlElementFlag.Closed); } HtmlWeb web = new HtmlWeb(); string url = String.Format("http://www.decodethis.com/VIN-Decoded/vin/{0}", vin); HtmlDocument doc = web.Load(url); var carDataNode = doc.DocumentNode.SelectSingleNode("//table[@class='cardata']"); DecodeThisResult result = new DecodeThisResult(); if (carDataNode != null) { result.YearMakeModel = carDataNode.SelectSingleNode("tr[2]/td[2]").InnerHtml + " " + carDataNode.SelectSingleNode("tr/td[@itemprop='manufacturer']").InnerHtml + " " + carDataNode.SelectSingleNode("tr/td[@itemprop='model']").InnerHtml; } else { try { result.YearMakeModel = doc.DocumentNode.SelectSingleNode("//span[@id='dnn_ctr500_VehicleIdPrime_lblName']").InnerHtml; } catch { result.YearMakeModel = ""; } } return(result); }