Scraping the shoe sizes with bs4

210 Views Asked by At

I am trying to scrape the shoes sizes of this shoe.https://www.mirapodo.de/tommy-hilfiger-gummistiefel-cognac-4545847.html. How can i scrape the value.

   <div class="grid-gap__m prod-info__size js-pdp-size">
                <form action="#">
          <div class="select-container prod-info__size-select-container  w100 ">
            <select class="ProdSizeSelect js-prod-variant-select" data-layer="js-layer-add-to-cart" name="selectsize" data-action="select-list" data-selected-sku="selectedSku" data-group-sku="4545847">
              <option value="select" data-add-to-notepad="allowed" selected="selected" data-disabled="disabled" disabled> Größe wählen</option>
                              <option value="4545848" data-add-to-notepad="allowed">36 (EU)</option>
                              <option value="4545849" data-add-to-notepad="allowed" data-offline="true" data-disabled="disabled">37 (EU) - Ausverkauft</option>
                              <option value="4545850" data-add-to-notepad="allowed">38 (EU)</option>
                              <option value="4545851" data-add-to-notepad="allowed" data-disabled="disabled">39 (EU) - Ausverkauft</option>
                              <option value="4545852" data-add-to-notepad="allowed" data-offline="true" data-disabled="disabled">40 (EU) - Ausverkauft</option>
                              <option value="4545853" data-add-to-notepad="allowed" data-disabled="disabled">41 (EU) - Ausverkauft</option>
                              <option value="4545854" data-add-to-notepad="allowed">42 (EU)</option>
                          </select>
          </div>
        </form>
      </div>
2

There are 2 best solutions below

1
On
from os import link, name
from os import system
import os
import requests
import json
from datetime import timedelta
from datetime import datetime
import csv
import time
from bs4 import BeautifulSoup as soup
from requests.models import ReadTimeoutError, Response
import colorama
from colorama import Fore, Back, Style
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from discord_webhook import DiscordWebhook, DiscordEmbed
from bs4 import BeautifulSoup as bs
import threading
import concurrent.futures


session = requests.session()

r = session.get("https://www.mirapodo.de/tommy-hilfiger-gummistiefel-cognac-4545847.html")

def get_sizes_instock():
    
    soup = bs(r, 'lxml')
    productscraper = soup.find('div',{'class':"ProdSizeSelect js-prod-variant-select"})
    allsizes = productscraper.find("value").text
    producttext = productscraper
    print(producttext)
0
On
from pprint import pp

import requests
from bs4 import BeautifulSoup


def main(url):
    r = requests.get(url)
    soup = BeautifulSoup(r.text, 'lxml')
    sizes = [x.text for x in soup.select(
        '.ProdSizeSelect option:nth-child(n+2)')]
    pp(sizes)


main('https://www.mirapodo.de/tommy-hilfiger-gummistiefel-cognac-4545847.html')

Output:

['36 (EU)',
 '37 (EU) - Ausverkauft',
 '38 (EU)',
 '39 (EU) - Ausverkauft',
 '40 (EU) - Ausverkauft',
 '41 (EU) - Ausverkauft',
 '42 (EU)']