Try to log in to Netflix automatically using python on your PC

Try logging in to Netflix automatically using python

at first Since this is my first post, I think there are many things that are missing, but please watch with warm eyes. In addition, since I am a beginner, I think that some parts of the code created by exploration may be difficult to understand, but please understand.

Overview

・ Operate the web using selenium

__ To the main subject __

Selenium is the one that can operate web pages with python. In this article, I will omit the environment construction and basic usage for operating Chrome via selenium with python.

Actually write the code

__Import webdriver from selenium __

For the time being, let's import the necessary modules

python:netflix.py


from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.action_chains import ActionChains
import time

When running the Web, import the time module to rest so that you do not specify the element before going to the next page.

python:netflix.py


driver = webdriver.Chrome("Specify the location where you saved the chrome driver")
#(Example) driver= webdriver.Chrome("C:\Command\chromedriver")
driver.get('https://www.netflix.com/jp/') 
time.sleep(1)

Now you can access the Netflix page for now. Of course, as an application, you can access other web pages by changing the part of https://www.netflix.com/jp/.

Enter characters by specifying __Path __ Next, write the code that lets you enter characters.

python:netflix.py


login = driver.find_element_by_css_selector('#appMountPoint > div > div > div > div > div > div.our-story-header-wrapper > div > a')
login.click()
#Go to login screen
driver.find_element_by_name('userLoginId').send_keys('mail address')
driver.find_element_by_name('password').send_keys('password')
#Enter your email address and password
driver.find_element_by_css_selector('#appMountPoint > div > div.login-body > div > div > div.hybrid-login-form-main > form > button').click()
time.sleep(1)

At this point, you're logged in to Netflix. However, from here on, the Path you specify depends on your Netflix contract plan, so I'll write the code in my case. As a matter of fact, if the code is written so far, you can specify the path and click, specify the path and input to go to automatic playback.

__ Until playback after login is completed __

Select yourself from here and repeat by specifying, clicking, and inputting the path until automatic playback.

python:netflix.py


driver.find_element_by_xpath('//*[@id="appMountPoint"]/div/div/div[1]/div[1]/div[2]/div/div/ul/li[1]/div/a/div/div').click()
time.sleep(1)
#Choose yourself
driver.find_element_by_xpath('//*[@id="appMountPoint"]/div/div/div[1]/div[1]/div[1]/div/div/div/div[1]/div/button/span').click()
#Click the search field
title ="Kengan Ashura"
driver.find_element_by_xpath('//*[@id="appMountPoint"]/div/div/div[1]/div[1]/div[1]/div/div/div/div[1]/div/div/input').send_keys(title)
time.sleep(1)
#Enter in the search field
driver.find_element_by_css_selector("#title-card-0-0 > div.ptrack-content").click()
time.sleep(2)
driver.find_element_by_css_selector("#pane-Overview > div > div > div > div.ptrack-content > div > div.jawbone-actions > a.playLink.isToolkit > button").click()
#Click play

This completes the Netflix autoplay code !!

At the end

Since I am a beginner, I think I can still simplify the code, but since it was completed at the beginning, I would appreciate your understanding. Next time, I would like to create a GUI with python, get a text box, and click a button to perform automatic playback.

Thank you for your relationship.

Recommended Posts

Try to log in to Netflix automatically using python on your PC
Try auto to automatically price Enums in Python 3.6
Try to improve your own intro quiz in Python
Try to put LED in your own PC (slightly)
Try to make it using GUI and PyQt in Python
How to log in to AtCoder with Python and submit automatically
Try using LevelDB in Python (plyvel)
Try to calculate Trace in Python
Try using Leap Motion in Python
Try logging in to qiita with Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try to operate Excel using Python (Xlwings)
Try text mining your diary in Python
Notes on using code formatter in Python
Create a shortcut to run a Python file in VScode on your terminal
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
Try to poke DB on IBM i with python + JDBC using JayDeBeApi
First steps to try Google CloudVision in Python
Try to implement Oni Maitsuji Miserable in python
Automatically register function arguments to argparse in Python
Try to separate Controllers using Blueprint in Flask
Email attachments using your gmail account in python.
Python: Try using the UI on Pythonista 3 on iPad
Notes on using dict in python [Competition Pro]
Try to automatically generate Python documents with Sphinx
Log in to Yahoo Business with Selenium Python
Try to calculate RPN in Python (for beginners)
Try working with Mongo in Python on Mac
To write to Error Repoting in Python on GAE
Try using ChatWork API and Qiita API in Python
Try using the DropBox Core API in Python
To automatically send an email with an attachment using the Gmail API in Python
Try to make a Python module in C language
[Unity (C #), Python] Try running Python code in Unity using IronPython
(Python) Try to develop a web application using Django
Steps to install the latest Python on your Mac
Dry-run sql query using psycopg2 on Redshift in Python
View images in OpenCV from Python using an external USB camera on your MacBook
How to allow nologin users to log in on Linux
Save your heart rate to SpreadSheets in real time (?) Using Python x fitbit API!
Try gRPC in Python
Post to your account using the API on Twitter
Create your first GDSII file in Python using gdspy
How to exit when using Python in Terminal (Mac)
[Road to intermediate Python] Define in in your own class
How to retrieve multiple arrays using slice in python.
Try to extract high frequency words using NLTK (python)
Try 9 slices in Python
Output to "7-segment LED" using python on Raspberry Pi 3!
How to execute a command using subprocess in Python
Try using Tweepy [Python2.7]
I get an error when I try to raise Python to 3 series using pyenv on Catalina
What to do if Jupyter Notebook on WSL does not start automatically in your browser
Try running Amazon Linux 2 on-premises (VM on your local PC).
Try to make PC setting change software using TKinter (beginner)
Try sorting your own objects with priority queue in Python
Try to operate an Excel file using Python (Pandas / XlsxWriter) ①
Try to operate an Excel file using Python (Pandas / XlsxWriter) ②
How to log in automatically like 1Password from the CLI
To return char * in a callback function using ctypes in Python