Created
February 26, 2016 09:48
-
-
Save Helgesmeby/97342f48ab46d5adfce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static Beer GetMetadataFromBeerAdvocate(Beer beer) | |
{ | |
var host = "http://www.ratebeer.com/"; | |
var searchUrl = "findbeer.asp"; | |
var param = "BeerName=" + beer.Title.Replace(" ", "+"); | |
var beerURL = ""; | |
using (WebClient wc = new WebClient()) | |
{ | |
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; | |
string HtmlResult = wc.UploadString(host + searchUrl, param); | |
beerURL = new Regex("<A HREF=\"/beer/" + beer.Title.ToLower().Replace(" ", "-") + "/\\d+/").Match(HtmlResult).Value; | |
beerURL = beerURL.Replace("<A HREF=\"", ""); | |
} | |
if (string.IsNullOrEmpty(beerURL)) | |
return beer; | |
using (WebClient wc = new WebClient()) | |
{ | |
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; | |
string HtmlResult = wc.UploadString(host + beerURL, param); | |
beer.ImageURL = new Regex("http://res.cloudinary.com/ratebeer/image/upload/\\w+,\\w+/beer_\\d+.jpg").Match(HtmlResult).Value; | |
beer.Score = new Regex("itemprop=\"ratingValue\">\\d+.\\d+").Match(HtmlResult).Value.Replace("itemprop=\"ratingValue\">", ""); | |
} | |
return beer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment