Introduction to Selenium

Pages that require the user to take actions to provide data (especially when URL is unchanged) cannot be scraped using "traditional methods". Selenium can be helpful in those cases. This notebook provides Selenium code to scrape roadpolice.am


In [21]:
from selenium import webdriver
import time

In [2]:
pin = "1848dsvyzjtw"
url = "https://offense.roadpolice.am/"

In [23]:
browser = webdriver.Chrome()
browser.get(url)
pin_space = browser.find_element_by_id("pin") #find pin input space
pin_space.send_keys(pin) #input pin
#pin_space.submit() #submit (press enter)
browser.find_element_by_tag_name("button").click() #or find the submit button and click
time.sleep(5) #wait for offense page to load
browser.find_element_by_link_text("Վերադառնալ").click()  #go back