This repository contains a Python script designed to scrape practice exam data from tests.com. The script uses Selenium to automate data collection, capturing detailed information about exam questions, options, and explanations. The extracted data is structured and exported to a CSV file for further analysis.
- Automated Navigation: The script automates the process of navigating through the practice exam, starting from login to completing the test.
- Question Data Extraction: Captures essential data such as:
- Patient demographic and presenting problem.
- Multiple-choice question text and answer options.
- Correct answer and explanation.
- Dynamic Element Handling: Utilizes Selenium's
WebDriverWaitto handle dynamic content and avoid interruptions. - CSV Export: Outputs the scraped data in a structured CSV format for easy analysis.
- Python: Ensure Python 3.x is installed.
- Libraries: Install the required Python libraries:
pip install selenium pandas
- WebDriver: Download the appropriate WebDriver for your browser (e.g., ChromeDriver for Google Chrome) and ensure it is accessible in your system's PATH.
Update the login function with your email and password for [tests.com]:
driver.find_element(By.ID, 'Email').send_keys('<your-email>')
driver.find_element(By.ID, 'pw').send_keys('<your-password>')Execute the script using:
python Webscraper.pyThe scraped data will be saved as a CSV file at the specified location:
/Users/ektaraj/Desktop/examfinal.csv
- Login: The script logs in to the website using the provided credentials.
- Data Scraping: It navigates through the exam, collecting:
- Scenario details
- Question text and answer options
- Correct answer and explanation
- Next Question: The script clicks the "Next" button to proceed to the following question, repeating the process until no questions remain.
- Export: All data is compiled into a pandas DataFrame and exported as a CSV.
The script is equipped with basic error handling to manage cases where elements are not found or questions are exhausted:
- If no more questions are available, the script will exit gracefully.
The CSV file contains the following columns:
- Source
- Exam Name
- Question #
- Case Study #
- Patient Demographic
- Presenting Problem
- Context
- Choice A, B, C, D
- Question
- Correct Answer
- Explanation Answer
- Ensure you have sufficient time to navigate the initial setup of the test before the script automates the process.
- The script requires manual intervention during the first step to set test preferences and start the exam.