Merge branch 'main' of /home/edward/git/eurotunnel-scrape

This commit is contained in:
Edward Betts 2023-08-11 11:38:37 +01:00
commit 6508de06f4

View file

@ -1,6 +1,7 @@
#!/usr/bin/python3 #!/usr/bin/python3
import os import os
import re
from datetime import date, datetime from datetime import date, datetime
from playwright.sync_api import Playwright, Request, expect, sync_playwright from playwright.sync_api import Playwright, Request, expect, sync_playwright
@ -57,14 +58,24 @@ def run(playwright: Playwright) -> None:
hr = HandleResponse() hr = HandleResponse()
page.on("requestfinished", hr.requestfinished) page.on("requestfinished", hr.requestfinished)
re_month_name = re.compile(r"^([A-Z][a-z]+) (\d{4})$")
page.goto("https://www.eurotunnel.com/uk/") page.goto("https://www.eurotunnel.com/uk/")
page.get_by_role("button", name="Accept All Cookies").click() page.get_by_role("button", name="Accept All Cookies").click()
page.get_by_role("textbox", name="Outbound").click() page.get_by_role("textbox", name="Outbound").click()
page.get_by_role("row", name="August 2023").get_by_role("cell").nth(1).click() month_row = page.get_by_role("row", name=re_month_name)
month_and_year = month_row.inner_text().strip()
if month_and_year == "August 2023":
month_row.get_by_role("cell").nth(1).click()
else:
assert month_and_year == "September 2023"
page.get_by_role("cell", name="29").click() page.get_by_role("cell", name="29").click()
page.get_by_role("textbox", name="Return").click() page.get_by_role("textbox", name="Return").click()
page.get_by_role("row", name="September 2023").get_by_role("cell").nth(2).click() page.get_by_role("row", name="September 2023").get_by_role("cell").nth(2).click()
page.get_by_role("cell", name="6", exact=True).click() page.get_by_role("cell", name="6", exact=True).click()
page.get_by_role("button", name="Search and book").click() page.get_by_role("button", name="Search and book").click()
page.get_by_label("Enter your vehicle registration").fill("KE69HRR") page.get_by_label("Enter your vehicle registration").fill("KE69HRR")
page.get_by_role("button", name="Find").click() page.get_by_role("button", name="Find").click()