Home > Back-end >  Cannot get quantity value from webpage source code
Cannot get quantity value from webpage source code

Time:10-17

I'm trying to get product in-stock counts from a webpage; the example product is as follows:

enter image description here

CodePudding user response:

The following code will try to get the value attribute of an input with quantity-num class:

r = requests.get('https://www.lightinthebox.com/en/p/wosawe-men-s-cycling-jacket-windbreaker-waterproof-rain-jacket-reflective-running-jackets-bike-hooded-packable-raincoat-top-lightweight-breathable_p8747531.html?category_id=799&prm=1.2.1.48')
 
soup = BeautifulSoup(r.content, 'html.parser')

s = soup.find('input', class_='quantity-num')

quantity = s.get('value')

Update:

To get the max quantity, look for the div with quantity-select class:

s = soup.find('div', class_='quantity-select')

max_quantity = s.get('data-max-quantity')
  • Related