how to access the first result of a google search result ( prominently a video link)?
Question: [https://www.google.co.in/search?q=black+sabbath+%E2%80%93+iron+man&oq=black+sabbath+%E2%80%93+iron+man&aqs=chrome..69i57.461j0j4&sourceid=chrome&es_sm=122&ie=UTF-8](https://www.google.co.in/search?q=black+sabbath+%E2%80%93+iron+man&oq=black+sabbath+%E2%80%93+iron+man&aqs=chrome..69i57.461j0j4&sourceid=chrome&es_sm=122&ie=UTF-8)

In the link provided above, the very first result is the video link to the
youtube, I want to access the link provided. How can I do that in python?

EDIT: My input will be a string that I query in the google-search box. Like in
this case "black sabbath iron man"


Answer: Scraping HTML is _fragile_ \-- yes you can do it with beautifulsoup4, e.g

    
    
    import bs4
    soup = bs4.BeautifulSoup(html_string)
    href = soup.find('h3').find('a').get('href')
    print(href)
    

will show
**/url?q=[http://www.youtube.com/watch%3Fv%3D9LjbMVXj0F8&sa=U&ei=ESCPVPD6NcT3yQS-04C4DA&ved=0CBQQtwIwAA&usg=AFQjCNGV1u7FshGW4K_Ffu0zLzwaW7sCzw](http://www.youtube.com/watch%3Fv%3D9LjbMVXj0F8&sa=U&ei=ESCPVPD6NcT3yQS-04C4DA&ved=0CBQQtwIwAA&usg=AFQjCNGV1u7FshGW4K_Ffu0zLzwaW7sCzw)**
or the like. However, the slightest cosmetic change to Youtube search results
might break your application.

Better to register your app with Google and use the provided API, as per
[Google's own docs](https://developers.google.com/youtube/v3/). The Python
client library nicely supports App Engine, see
<https://developers.google.com/youtube/v3/code_samples/python_appengine> for
example.

