Search code examples
pythonpython-3.xpython-requestsrequestpython-requests-html

Python: how to monitor availability ecommerce products for all sub products selectable?


I wanna to scrape the following product https://www.decathlon.it/p/disco-ghisa-bodybuilding-28mm/_/R-p-7278?mc=1042303&c=NERO

But for the product we could select different weight (from 0.5 to 20kg). I have created the following code, but It give me only the first weight (0,5kg) and not the other one.

import requests
import re
import time

urls = ['p/disco-ghisa-bodybuilding-28mm/_/R-p-7278.html']
user_agent = {'User-agent': 'Mozilla/5.0'}

def main(site):
    with requests.Session() as req:
        for url in urls:
            r = req.get(site.format(url), headers=user_agent)
            match = re.search('availability.+org\/(.*?)"', r.text)
            print("url: {:<70}, status: {}".format(r.url, match.group(1)))

while True:
    main("https://www.decathlon.it/{}")
    time.sleep(1)                          

But I wanna to figure out the following output

weight 0,5kg outofstock, 1kg outofstock and so on. 

Solution

  • You should probably check BeautifulSoup python library and discussion from this link Unable to scrape drop down menu using BeautifulSoup and Requests or use Selenium just to change option from dropdown menu what you can learn more about here https://www.guru99.com/select-option-dropdown-selenium-webdriver.html