private AmazonProduct GetContent(String ASin) { var content = ""; var client = new WebClient(); var headers = new WebHeaderCollection(); headers.Add(HttpRequestHeader.Accept, "text/html, application/xhtml+xml, */*"); //headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"); client.Headers = headers; var rawhtml = client.DownloadString("http://www.amazon.co.uk/dp/"+ ASin); HtmlAgilityPack.HtmlDocument Html = new HtmlAgilityPack.HtmlDocument(); Html.LoadHtml(rawhtml); var title = GetTitle(Html); var description = GetDescription(Html); AmazonProduct prod = new AmazonProduct() { Description = description, Title = title }; return prod; }
public HttpResponseMessage Get(string ASin) { var res = new HttpResponseMessage(); AmazonProduct content = GetContent(ASin); res.StatusCode = HttpStatusCode.OK; res.Content = new ObjectContent(typeof(AmazonProduct), content, new System.Net.Http.Formatting.XmlMediaTypeFormatter()); return(res); // new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); }
private AmazonProduct GetContent(String ASin) { var content = ""; var client = new WebClient(); var headers = new WebHeaderCollection(); headers.Add(HttpRequestHeader.Accept, "text/html, application/xhtml+xml, */*"); //headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate"); headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB"); headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"); client.Headers = headers; var rawhtml = client.DownloadString("http://www.amazon.co.uk/dp/" + ASin); HtmlAgilityPack.HtmlDocument Html = new HtmlAgilityPack.HtmlDocument(); Html.LoadHtml(rawhtml); var title = GetTitle(Html); var description = GetDescription(Html); AmazonProduct prod = new AmazonProduct() { Description = description, Title = title }; return(prod); }