Scraping with Authentication

KELAS DATA SCRAPING




Kampus Remote Worker Indonesia | 2024

Data Scraping | rianaditro

Introduction

When scraping data from websites, you will often encounter authentication mechanisms that protect content behind login forms or API credentials.

if user.logged_in: print("Success!")
Data Scraping | rianaditro

Automate Login vs Payload

Automate Login using Selenium

driver = webdriver.Chrome(options=options)
driver.get(url)

username = driver.find_element(By.ID, "email")
username.send_keys("admin@example.com")

password = driver.find_element(By.ID, "password")
password.send_keys("password")

submit_button = driver.find_element(By.ID,"submit-button")
submit_button.click()
Data Scraping | rianaditro

Login using Requests Payload

payload = {
            "email": "admin@example.com",
            "password": "password",
        }

response = requests.post(url, data=payload)
Data Scraping | rianaditro

Class Activity

Create an account on https://webapi.bps.go.id/developer/ then automate your login process using both of selenium and requests payload.

Data Scraping | rianaditro

Learn More

Join us on this self-study journey! Click the link below to get started.

Data Scraping | rianaditro

Discover Advanced Topic

Master this advanced topic and supercharge your skills.

Data Scraping | rianaditro

Homework Assignment

Find any website that using login and try login using the best approach!

Data Scraping | rianaditro




Thank you

Any Question?




Kampus Remote Worker Indonesia | 2024

Data Scraping | rianaditro

<br>

<br>