By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,369 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,369 IT Pros & Developers. It's quick & easy.

How to display web search results with links by some WPF program?

P: 1
Hi everyone,

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
  1. bool search_end = false, page_se = false;
  2. byte page = 0; // Search result's index
  3. while (!search_end)
  4. {
  5.     try
  6.     {
  7.         while (!page_se)
  8.         {
  9.             try
  10.             {
  11.                 Run title = new Run(phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("title")).Text); // Site's title
  12.                 Hyperlink hyperlink = new Hyperlink(title) 
  13.                 {
  14.                     NavigateUri = new Uri(phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("url")).Text)
  15.                 };
  16.                 Results.Inlines.Add(hyperlink); // Results - TextBlock's name | Adding website's title connected to hyperlink
  17.                 Results.Text += Environment.NewLine;
  18.                 Results.Text += phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("url")).Text + Environment.NewLine; // Site's URL
  19.                 Results.Text += phantomDriver.FindElements(By.ClassName("result")).ElementAt(page).FindElement(By.ClassName("desc")).Text + Environment.NewLine + Environment.NewLine; // Site's description
  20.                 ++page; // Scraping data from next result
  21.             }
  22.             catch
  23.             {
  24.                 page_se = true; // Stop scraping data from current page 
  25.             }
  26.         }
  27.         phantomDriver.FindElement(By.ClassName("next")).Click(); // Navigate to next page of search results
  28.         page = 0;
  29.     }
  30.     catch // Closing PhantomJS
  31.     {
  32.         phantomDriver.Quit();
  33.         search_end = true;
  34.     }
  35. }
  36.  
Jan 23 '20 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.