Advanced Dynamic Webscraping
Prompt
You are a senior Python developer and expert in web scraping tasked with creating a professional, production-ready Python script to extract all relevant, structured data from the dynamic website https://agents.sabrina.dev/ and export it into a well-organized CSV file. Your solution must: 1. **Data Extraction Requirements:** - Identify and extract all structured data elements visible on the site, including agent names, IDs, performance metrics, and any associated metadata. - Because the site dynamically loads data (as indicated by dynamic content analysis), use Selenium or other browser automation to render JavaScript content fully. - Handle any pagination, infinite scroll, or dynamic loading mechanisms to ensure complete data coverage. - Respect the robots.txt and website’s terms of service; the robots.txt currently allows scraping. - Implement robust error handling covering network issues, element detection failures, and potential rate limiting. 2. **Data Structuring:** - Clean, normalize, and standardize the data, handling missing or null values appropriately. - Organize extracted data into clear, logical columns with descriptive headers. - Preserve any hierarchical or relational aspects of the data present on the website. 3. **Technical Implementation:** - Use Python with libraries such as Selenium for scraping dynamic content, BeautifulSoup for HTML parsing, requests (if needed), and pandas for data organization. - Implement session management if login/authentication is required (currently not indicated). - Mimic human browsing with randomized delays and appropriate HTTP headers. - Write clear, modular, and well-commented code maintaining professional coding standards. 4. **Output Requirements:** - Export the data as a UTF-8 encoded CSV file suitable for analysis. - Include a timestamp or version tag in the output filename to track scrape versions. 5. **Documentation & Maintainability:** - Provide concise inline comments explaining key code sections. - Include instructions or notes on configuring or customizing the script for future modifications. # Steps - Inspect the target website’s DOM structure after full page load using Selenium. - Identify containers or cards representing each agent’s data. - Loop through all dynamically loaded content/pages to extract data. - Normalize and validate extracted fields. - Store results in a pandas DataFrame. - Export DataFrame to CSV with timestamp. - Add logging and try-except blocks to handle exceptions and retries. # Output Format - A fully functional Python script file (.py) implementing the above requirements. - The script outputs a UTF-8 encoded CSV file with timestamped filename. - The script includes clear comments and instructions. # Notes - No login/authentication appears required but prepare code structure for easy extension. - Because static content analysis shows no direct tables or JSON-LD, rely on Selenium to capture dynamic content. - Respect robots.txt which permits scraping. - Use human-like browsing patterns to avoid rate-limiting or blocking. Your final response should be the complete, best-practice Python script and associated documentation to enable robust, maintainable, and comprehensive scraping of https://agents.sabrina.dev/.
Related Coding Prompts
Write Code
As a seasoned programmer, your task is to write code in [programming language] to [perform action]. The code should be efficient, well-structured, and optimized for performance. Make sure to follow best practices and industry standards while implementing the necessary algorithms and logic to achieve the desired functionality. Test the code thoroughly to ensure it functions as intended and meets all requirements. Additionally, document the code properly for future reference and maintenance.
Debug Code
Act as a seasoned programmer with over 20 years of commercial experience. Analyze the provided [piece of code] that is causing a specific [error]. Your task involves diagnosing the root cause of the error, understanding the context and functionality intended by the code, and proposing a solution to fix the issue. Your analysis should include a step-by-step walkthrough of the code, identification of any bugs or logical mistakes, and a detailed explanation of how to resolve them. Additionally, suggest any improvements or optimizations to enhance the performance, readability, or maintainability of the code based on your extensive experience. Ensure that your solution adheres to best practices in software development and is compatible with the current development environment where the code is being executed.
Do Code Review
As a seasoned programmer with over 20 years of commercial experience, your task is to perform a comprehensive code review on the provided [piece of code]. Your review should meticulously evaluate the code's efficiency, readability, and maintainability. You are expected to identify any potential bugs, security vulnerabilities, or performance issues and suggest specific improvements or optimizations. Additionally, assess the code's adherence to industry standards and best practices. Your feedback should be constructive and detailed, offering clear explanations and recommendations for changes. Where applicable, provide examples or references to support your suggestions. Your goal is to ensure that the code not only functions as intended but also meets high standards of quality and can be easily managed and scaled in the future. This review is an opportunity to mentor and guide less experienced developers, so your insights should be both educational and actionable.