Search code examples
pythonspeech-recognition

Open a link of search result in Google or YouTube using Python automatically


I am creating a speech assistant using speech_recognition in Python. So far I am able to get the search results in Google and YouTube, by giving input voice commands.

But How do I open the links of these search results?

For Example, please refer the picture below:

enter image description here

In the above screenshot shows the search results for: "open the first link form Google search results using Python". I would like to open the first link of stackoverflow.com automatically.

I would also like to do the same thing with YouTube search results.

Please guide me with the proper approach to accomplish this.

Thank you all in advance.


Solution

  • Use BeautifulSoup!

    1. Download the page using requests
    2. Parse the HTML using BeautifulSoup
    3. Look through the HTML for a way to identify the tags with the page.find_all('a', href=True) function