enter an address into the form, found on this website: https://www.gateshead.gov.uk/article/3150/bin-collection-day-checker, submit it then process the output in python

To enter an address into the form found on the website, we will use the selenium library in Python to drive a web browser and fill out the form using XPath to locate the form elements. Here's the code to do so:

main.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup

# set up the webdriver (you may need to download the appropriate driver for your browser)
driver = webdriver.Chrome()
driver.get("https://www.gateshead.gov.uk/article/3150/bin-collection-day-checker")

# find the address input field and submit button
address_input = driver.find_element_by_xpath('//*[@id="edit-add1"]')
submit_button = driver.find_element_by_xpath('//*[@id="edit-submit"]')

# enter the address and submit the form
address_input.send_keys("123 Main St")
submit_button.click()

# process the output using BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'html.parser')
result_tables = soup.find_all('table', {'class': 'collection-day-table'})

# do something with the result_tables...
817 chars
22 lines

This code uses find_element_by_xpath to locate the input field and submit button on the form, and then send_keys to enter the address and click to submit the form. The resulting HTML is then loaded into BeautifulSoup, where you can use it to extract relevant information.

Note that you will need to download and install both selenium and beautifulsoup before running this code. Additionally, you will need to download the appropriate webdriver for your browser and operating system.

gistlibby LogSnag