I just want it to past the first page by selecting “1” from the dropdown menu and clicking on “Weiter” but I couldn’t even get it to find the menu so I tried to make it send the data directly to the server and jump to the next page where the appointments should be then showned. But I am getting the message “Access denied to this page (403)” from Microsoft Edge… What should I do? I have actually no idea of what I am doing… I’ve been using ChatGPT to help me with the code. Thanks!
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.edge.service import Service
from selenium.webdriver.edge.options import Options
import time
Path to the Microsoft Edge WebDriver
webdriver_path = “C:UsersthejaDesktopBotmsedgedriver.exe”
URL of the website
url = “https://stadt.muenchen.de/terminvereinbarung_/terminvereinbarung_abh.html?cts=1000113”
Set up the Edge WebDriver with a custom User-Agent
options = Options()
options.headless = False # Run in normal mode to see the browser
options.add_argument(“user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36”)
service = Service(webdriver_path)
driver = webdriver.Edge(service=service, options=options)
try:
# Open the website
driver.get(url)
# Wait for the page to load completely
wait = WebDriverWait(driver, 20) # Increased wait time
wait.until(EC.presence_of_element_located((By.TAG_NAME, “body”)))
# Execute JavaScript to submit the form
script = “””
var form = document.createElement(‘form’);
form.method = ‘POST’;
form.action = ‘https://stadt.muenchen.de/terminvereinbarung_/terminvereinbarung_abh.html?cts=1000113’;
var token = document.createElement(‘input’);
token.type = ‘hidden’;
token.name = ‘FRM_CASETYPES_token’;
token.value = ‘397017935ccff9a3e347532ef2898855’;
form.appendChild(token);
var step = document.createElement(‘input’);
step.type = ‘hidden’;
step.name = ‘step’;
step.value = ‘WEB_APPOINT_SEARCH_BY_CASETYPES’;
form.appendChild(step);
var caseType = document.createElement(‘input’);
caseType.type = ‘hidden’;
caseType.name = ‘CASETYPES[Notfalltermin UA 35]’;
caseType.value = ‘1’;
form.appendChild(caseType);
document.body.appendChild(form);
form.submit();
“””
driver.execute_script(script)
# Wait for the next page to load
wait.until(EC.presence_of_element_located((By.TAG_NAME, “body”)))
# Keep the browser open for further actions
print(“Browser will remain open. Press Ctrl+C to exit.”)
while True:
time.sleep(1)
except Exception as e:
print(f”An error occurred: {e}”)
driver.save_screenshot(“error_screenshot.png”) # Save a screenshot of the error
Do not close the browser, keep it open for further actions
Source: Read More