So I am writing a c# program where the user can search for and watch youtube videos based on keywords. The user types their intended term into the search box, and then the program loads a list of videos with their intended search term. But I am wondering, is there a way to code it to click on the first - third video link when the search happens? I am also looking for it to close the current browser tab before opening the next.
Here is the code:
string[] words = {searchterms.text};
Console.WriteLine("Current word being searched for at " DateTime.Now ": " words[r.Next(0, words.Length)]);
Console.WriteLine("Number of searches made since start: " searchcount .ToString());
string word = words[r.Next(0, words.Length)];
NameValueCollection nameValueCollection = new NameValueCollection();
nameValueCollection.Add("q", word);
webClient.QueryString.Add(nameValueCollection);
var youtubesearch = new ProcessStartInfo
{
FileName = "https://www.youtube.com/results?search_query=" word,
UseShellExecute = true
};
Process.Start(youtubesearch);
Thank you.
CodePudding user response:
If you're working on a Console app, you should know that the windows' shell do not support hyperlinks, which means you can't.
But i'm only deducing you're working on a Console app because of the Console.WriteLine() in your code, so could you be more specfifc ?
CodePudding user response:
Well, you can display the links in a label in order to be opened by the user in the browser, but if you want to display all the research results of youtube in your app, i think you have 2 solutions :
- You can add an element called Web Browser, which is a web browser that will be displayed in your app (and you give it your URL
- You also can work with the YouTube APIs. You can call an API using a link, and it will return you some non-displayable data, in JSON format usually, which you can use to display a list of the search result. You can maybe have the covers, tht title, description, etc of a video. I don't know how the YouTube APIs work, so here's a link so you can do some research of your own