Let’s Automate | Python

Holla Hackers,

Today we are going to talk about Automating things around you using python.

So, I guess most of you are already familiar with python if not this is a time to learn something new. Today we will talk more about how we can make our life easy with python, We will learn about automating things.

What exactly is automation and what I’m talking about?
Automation simply means making something do itself like you have a job to rename 100 files in a folder why do it yourself let computer help you [Here is the code for same].

Why python for automation?
Python is a scripting language, and scripting languages that mean it need not get compiled and can be run on any system.
Python is open-source, very simple and has some great library’s that you can use to make your program easily.

Ok, Let’s Do Some Coding…. 

Today we will build a python script which can play youtube video on your browser if you pass a video title isn’t it cool?

Let’s get started….

Step1: We need a youtube link (link to the video we want to play in browser):

For that, we will do a bit of Web Scraping  using beautiful soup

Let’s search for something on youtube

 

nape we can do this from a url
https://www.youtube.com/results?search_query=justin+bieber

Next:

We just need to extract link of the first video

from bs4 import BeautifulSoup
import requests
def toplink(search):
SearchUrl=str('https://www.youtube.com/results?search_query='+search)
page=requests.get(SearchUrl)
soup = BeautifulSoup(page.text, "lxml")
print(page)
link=soup.findAll(attrs={'class':'yt-uix-tile-link'})
links=link[0]
return ('https://www.youtube.com' + links['href'])

This will get the link of the Video now we just need to play that on the browser I would say you should try to do that yourself for help let me tell you there is a library that can help you webbrowser .

There is already a library that does the same and was publishes by me here . Hope you like and enjoy this tutorial.

Questions? Ask in comments below 🙂

omkar yadav Written by:

@omi10859 Omkar is a geek, love to know more about things going around, In his free time he loves to watch Sci-fi and talk about impossible.

One Comment

  1. November 27, 2018
    Reply

    I really enjoy examining on this internet site, it contains excellent articles.

Leave a Reply

Your email address will not be published. Required fields are marked *