I want to create a WPF app that could display web search results with active links to sites, like Bing. I'm using a headless browser PhantomJS for scraping data from Qwant Lite's search results.
Now on the app's window is text which contains only a few results, for example:
Forest - Wikipedia (website's title - it's not connected with hyperlink, but should be)
https://en.wikipedia.org/wiki/Forest (URL)
A forest is a large area dominated by trees. Hundreds of more precise definitions of forest are used throughout the world, incorporating factors such as tree density, tree height, land use, legal standing and ecological function. (site's description)
I have noticed that program displays all found websites' titles (along with URLs and descriptions) when they haven't NavigateUri property. They aren't however references to websites.
How to display all results found by PhantomJS with links?
Expand|Select|Wrap|Line Numbers
- bool search_end = false, page_se = false;
- byte page = 0; // Search result's index
- while (!search_end)
- {
- try
- {
- while (!page_se)
- {
- try
- {
- Run title = new Run(phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("title")).Text); // Site's title
- Hyperlink hyperlink = new Hyperlink(title)
- {
- NavigateUri = new Uri(phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("url")).Text)
- };
- Results.Inlines.Add(hyperlink); // Results - TextBlock's name | Adding website's title connected to hyperlink
- Results.Text += Environment.NewLine;
- Results.Text += phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("url")).Text + Environment.NewLine; // Site's URL
- Results.Text += phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("desc")).Text + Environment.NewLine + Environment.NewLine; // Site's description
- ++page; // Scraping data from next result
- }
- catch
- {
- page_se = true; // Stop scraping data from current page
- }
- }
- phantomDriver.FindElement(By.ClassName("next")).Click(); // Navigate to next page of search results
- page = 0;
- }
- catch // Closing PhantomJS
- {
- phantomDriver.Quit();
- search_end = true;
- }
- }