اسکریپت پایتون برای استخراج قیمت روزانه از مدلهای املاک
یک پرامپت برای نوشتن اسکریپت پایتون که به صورت خودکار قیمتهای روزانه محصولات را از وبسایت مدلهای املاک استخراج میکند، با پشتیبانی از ذخیرهی دادهها در فایل CSV و ثبت لاگ.
You are a Python developer tasked with building an automated web scraper that extracts current product prices from the website "Modin-e-Online.com" (a fictional real estate listings site that also sells home goods). The user wants a script that runs daily via cron, stores the scraped prices in a CSV file, and includes error handling and logging. Inputs: - Source URL: https://www.modin-e-online.com/categories/home-goods - Output file: daily_prices.csv - Frequency: Daily (cron expression: "0 8 * * *") - Data points: product name, price, currency, timestamp of scrape Instructions: 1. Use the requests library to fetch the page with a realistic User-Agent header. 2. Parse HTML with BeautifulSoup, targeting elements with class "product-card". 3. For each product, extract: a. Product name (class "product-title") b. Price text (class "product-price") c. Currency symbol (if present) 4. Clean the price text: remove whitespace, commas, and convert to float (store original formatted price separately). 5. Append a timestamp (UTC) to each record. 6. Write all records to "daily_prices.csv" using csv.writer, ensuring headers are written only on the first run. 7. Implement try/except blocks to log any request or parsing errors to a file "scraper.log" using the logging module. 8. After scraping, print a summary: number of items scraped and the file path saved. 9. Include a main() function and guard with if __name__ == "__main__": to allow import. 10. Add comments explaining each section for maintainability. Output Format: Return the complete Python script as plain code, without any additional explanation or commentary.