Home Apple e mail – SAVE THE HTML PAGE USING PYTHON

e mail – SAVE THE HTML PAGE USING PYTHON

0
e mail – SAVE THE HTML PAGE USING PYTHON

[ad_1]

from selenium import webdriver
from selenium.webdriver.frequent.by import By
import os
#import time

login_url = “https://stureg.ioqmexam.in/Login”
dob = “01/01/2009” # Use a particular date for testing

output_directory = “html_pages”
image_directory = “photos”
os.makedirs(output_directory, exist_ok=True)
os.makedirs(image_directory, exist_ok=True)

driver = webdriver.Firefox()

strive:
# Navigate to the login web page
driver.get(login_url)

# Find parts
username_field = driver.find_element(By.NAME, "RegNo")
password_field = driver.find_element(By.NAME, "DOB")
login_button = driver.find_element(By.XPATH, '//*[@id="counts"]/div/div/div[2]/div/div/div/div/div/div/div/type/div[3]/div[2]/button')

# Fill in credentials
username_field.clear()
username_field.send_keys("YourRegNo")  # Substitute with a legitimate registration quantity
password_field.clear()
password_field.send_keys(dob)

# Click on login button
login_button.click on()

# Introduce a delay to permit the web page to load (you'll be able to regulate the sleep period as wanted)
#time.sleep(5)

# Save the web page supply as an HTML file
page_source = driver.page_source
html_file_path = os.path.be part of(output_directory, "test_page.html")
with open(html_file_path, "w", encoding="utf-8") as html_file:
    html_file.write(page_source)

# Seize and save your complete browser window as a picture
browser_screenshot_path = os.path.be part of(image_directory, "test_browser_screenshot.png")
driver.save_screenshot(browser_screenshot_path)

print(f"HTML file saved at: {html_file_path}")
print(f"Browser screenshot saved at: {browser_screenshot_path}")

besides Exception as e:
print(f”An error occurred: {e}”)

lastly:
# Shut the Firefox WebDriver
driver.give up()

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here