public static IEnumerable <IWebElement> RankWikiLinks(this RemoteWebDriver driver, string key) { var wikiLinks = LinkFinders.FindWiki(driver); return(from link in wikiLinks orderby link.Text.FindSimilarity(key) descending select link); }
public static MovieInfo GetMovieInfo(string movieName, string outputDirectory) { MovieInfo info = new MovieInfo() { Name = movieName }; ChromeOptions options = new ChromeOptions(); //options.AddArgument("headless"); using (ChromeDriver chrome = new ChromeDriver(Environment.CurrentDirectory, options)) { //Search Movie Searcher searcher = new Searcher(driver: chrome, urlBuilder: SearchUrlBuilders.Bing, parsers: (driver) => LinkFinders.FindWiki(driver).RankLinks(movieName)); var result = searcher.Search($"{movieName} film").Select(link => link.GetAttribute("href")).ToList(); foreach (var link in result) { try { info.WikiLink = link; chrome.Navigate().GoToUrl(info.WikiLink); chrome.WaitForPageLoad(); //Extract Info info.WikiScreenShotPath = Path.Combine(outputDirectory, $"{movieName}_wiki.png"); chrome.GetScreenshot().SaveAsFile(info.WikiScreenShotPath); WikiParser wp = new WikiParser(chrome); info.Directors_Wiki = wp.GetDirectors(); //Extract Info var imdbLink = LinkFinders.FindImdb(chrome)?.Reverse()?.First(); info.ImdbLink = imdbLink.GetAttribute("href"); chrome.Navigate().GoToUrl($"{info.ImdbLink}fullcredits"); info.ImdbScreenShotPath = Path.Combine(outputDirectory, $"{movieName}_imdb.png"); chrome.GetScreenshot().SaveAsFile(info.ImdbScreenShotPath); ImdbParser ip = new ImdbParser(chrome); info.Directors_Imdb = ip.GetDirectors(); break; } catch (Exception e) { Console.WriteLine($"{movieName}" + e.Message); } } } return(info); }