public static WebPageParser FromUrl(string url) { if (url == "") { return(WebPageParser.FromString(fallBackPage)); } else { WebPageParser foo = new WebPageParser(); if (url.IndexOf("http://") < 0 && url.IndexOf("https://") < 0 || (url.IndexOf(".") < 0)) { url = "http://" + url; } if (foo.browser == null) { foo.browser = new HtmlWeb(); } if (foo.client == null) { foo.client = new WebClient(); } try { try { foo.document = foo.browser.Load(url); } catch (UriFormatException e) { foo = WebPageParser.FromString(fallBackPage); } foo.url = url; } catch (Exception e) { foo = WebPageParser.FromString(fallBackPage); } return(foo); } }
public static WebPageParser FromString(string pagecontent) { WebPageParser foo = new WebPageParser(); if (foo.browser == null) { foo.browser = new HtmlWeb(); } if (foo.client == null) { foo.client = new WebClient(); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(pagecontent); foo.document = doc; return(foo); }
public LevelGen(string url) { //while (true) { Console.WriteLine("Creating web page parser"); try { //String uri = Console.ReadLine(); //if (uri.Equals("q")) Environment.Exit(1); web = WebPageParser.FromUrl(url); } catch (Exception e) { Console.WriteLine(e.Message); web = new WebPageParser(); } Console.WriteLine("Web page parser created successfully"); this.GetLevel(web.GetTotalWebsiteElements()); this.MakeDoors(Math.Min((LevelGrid.GetLength(0) + LevelGrid.GetLength(1)) / 2, web.GetAllLinks().Count)); this.title = web.GetWebpageTitle(); this.colors = GetAllColors(web); this.primaryColor = getMostColorful(this.colors); //} }
private List <Color> GetAllColors(WebPageParser wbpp) { List <Color> AllColors = new List <Color>(); foreach (string hexcode in wbpp.GetAllWebpageColors()) { AllColors.Add(ParseColor(hexcode)); } AllColors.Sort(delegate(Color a, Color b) { if (GetColorfulnessIndex(a) > GetColorfulnessIndex(b)) { return(1); } else if (GetColorfulnessIndex(a) == GetColorfulnessIndex(b)) { return(0); } else { return(-1); } }); return(AllColors); }