Skip to content

Instantly share code, notes, and snippets.

@connorwilloughby
Last active March 14, 2025 00:21
Show Gist options
  • Select an option

  • Save connorwilloughby/bde781db1bd57d89bf894055bce5eb93 to your computer and use it in GitHub Desktop.

Select an option

Save connorwilloughby/bde781db1bd57d89bf894055bce5eb93 to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.webdriver.common.by import By
import json
from time import sleep
from selenium.common.exceptions import NoSuchElementException
BASE_URL = "https://healthclinics.superdrug.com/travel-vaccinations/"
driver = webdriver.Chrome()
def reject_cookies():
driver.get(BASE_URL)
sleep(1)
reject_button = driver.find_element(
By.ID, "onetrust-reject-all-handler"
)
reject_button.click()
def get_countries() -> list:
driver.get(BASE_URL)
country_a_tags = driver.find_elements(
By.XPATH, "//div[contains(@class, 'accordion-content')]//a"
)
country_links = [[link.get_attribute("href"), link.get_attribute("innerText")] for link in country_a_tags]
return country_links
def get_country_suggestions(page: str) -> dict:
driver.get(page)
try:
certificate_tag = driver.find_element(By.CLASS_NAME, "hc-tv-single-certificate")
yellow_fever_text = certificate_tag.text
except NoSuchElementException:
yellow_fever_text = None
vaccination_tags = driver.find_elements(By.XPATH, "//dl//dt//a")
vaccinations = [tag.text.rsplit(" £", 1)[0] for tag in vaccination_tags]
suggestions = {
"yellow_fever": yellow_fever_text,
"recommendations": vaccinations,
}
return suggestions
if __name__ == "__main__":
reject_cookies()
suggestions = {}
countries = get_countries()
for country in countries:
suggestions[country[1]] = get_country_suggestions(country[0])
write = json.dumps(suggestions)
with open('data.json', 'w', encoding='utf-8') as f:
json.dump(suggestions, f, ensure_ascii=False, indent=4)
print("BREAK")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment