Forum Discussion
Lbegue
Oct 26, 2023Copper Contributor
Automatisation d’achat en ligne
Bonjour la communauté,
Ayant l’habitude de faire mes courses en ligne, j’ai eu une idée assez farfelue qui est d’automatiser mes achats de courses en ligne.
en effet, j’aimerais faire un script qui, a partir d’un bon de commande, pourrait aller sur les site web défini dans une variable de type tableau (exemple: Carrefour,E.Leclerc,Intermarché) comparer les prix et ajouter les articles les moins dans le panier du site associé.
J’ai d’assez bonne notions de PowerShell mais étant autodidacte et n’ayant jamais exploité de données web (web scraping). Je viens à vous pour vous demander si c’était faisable, si oui par où commencer ? Dois-je associer d’autre language avec celui de PowerShell ? Si oui lesquels ?
Mes compétences se limitent vraiment au PowerShell dans la partie web c’est pour cela que je vous demande conseil.
En vous remerciant d’avance pour vos réponse.
Cordialement
BEGUE Ludovic
- LeonPavesicSilver Contributor
Hi Lbegue,
Automating online grocery shopping is a interesting idea.Automating Online Grocery Shopping:
Automating online grocery shopping can be a time-saving and convenient way to ensure you always have the essentials on hand. While it may seem daunting at first, with the right approach and tools, you can easily create a script to handle this task for you.
Understanding the Legal and Ethical Aspects
Before embarking on this project, it's crucial to familiarize yourself with the terms of service of the websites you plan to scrape. Some websites may prohibit scraping or have specific usage policies. Ensure that your project adheres to all legal and ethical standards.
Learning About Web Scraping
Web scraping involves extracting data from websites. To accomplish this, you can utilize libraries like BeautifulSoup (for Python) or Invoke-WebRequest (for PowerShell). These libraries enable you to access and extract information from web pages.
Choosing a Programming Language
While you may prefer PowerShell, web scraping is more commonly done using languages like Python. Python offers a rich ecosystem of libraries and tools for web scraping, such as Beautiful Soup, Scrapy, and Selenium, which can simplify your task. Consider using Python if you're open to it.
Selecting a Headless Browser
Many websites rely on JavaScript to load content dynamically. To interact with such websites, you might need a headless browser automation tool. In Python, you can use tools like Selenium or Puppeteer to automate the process of visiting websites, clicking buttons, and navigating through pages.
Creating Your Script
Develop a script that performs the following steps:
- Load the list of websites and their corresponding URLs from your defined variable.
- Visit each website using a headless browser.
- Search for the products you need on each site and extract their prices.
- Keep track of the prices and product details.
- Determine which website offers the best prices for each product.
- Add the products to the cart on the website with the lowest price.
Handling User Authentication
If any of the websites require you to log in to your account before making a purchase, you'll need to handle user authentication in your script. Consider using secure password management techniques to store and retrieve your credentials safely.
Testing and Debugging
Thoroughly test your script on a small scale before scaling it up. Make sure it navigates the websites correctly, adds the right products to the cart, and handles errors gracefully.
Scheduling and Automation
To automate your online grocery shopping, you can schedule your script to run at specific times or triggers (e.g., every week on a specific day). This can be done using built-in task scheduling tools on your operating system.
Keeping Maintenance in Mind
Be prepared to update your script regularly, as websites may change their structure or terms of service, which could break your automation.
Security
Handle sensitive data (e.g., login credentials) with care and ensure that your automation is secure. Consider using secure password management techniques and encryption methods when necessary.
Recommended Resources:
Beautiful Soup: https://tedboy.github.io/bs4_doc/
Scrapy: https://docs.scrapy.org/en/latest/intro/tutorial.html
Puppeteer: https://github.com/puppeteer/puppeteer