472,782 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,782 software developers and data experts.

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

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. }
Jan 23 '20 #1
0 2224

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

Similar topics

by: Alexandre Plennevaux | last post by:
hello mates, i want to set up a searchable database out of a huge word document containing reglementary articles (75 pages). The way i want the system to work is as such: a search form...
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
by: Noticedtrends | last post by:
Can inference search-engines narrow-down the number of often irrelevant results, by using specific keywords; for the purpose of discerning emerging social & business trends? For example, if...
by: Dica | last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still trying to wrap my brain around .net coding habits. in classic asp, if i wanted to show search results, i'd just post the...
by: =?Utf-8?B?Qm9ubmll?= | last post by:
I have a basic ASP / Index Server search page. I have a web site contained in a subdirectory in the root of a main web site. What I’m trying to do is force the search page in the subdirectory,...
by: dougmeece | last post by:
Good day everyone, I have a database with 2 main forms. The first form is used to add records to the database and contains a command button that opens the 2nd form for records searching. On...
by: moorcroft | last post by:
Hi I have developed an application that people can use to search for planning applications. The way it works is that once search criteria has been selected and submit is hit, the server will save...
by: geforceGTX480 | last post by:
So, I can't seem to get a sample code that works. I have a web form that will have input fields. These fields will be used as input parameters for the MSSQL stored procedure. From there we are...
by: fadee2 | last post by:
hyy all I m new to C#, so please ignore if I use wrong terms. I m working on a single form application in VS2010, with sql database. I have successfully inserted the data in to database table. ...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.