James Carlton
James Carlton

Reputation: 21

How can I access a JSON Object in HTML with python?

Hello i hope someone can help me solve the issue I am encountering. I am trying to access a JSON object inside the HTML. Below i will attach the HTML (a shortened version bc the JSON output is huge) and my attempt.

HTML :

    <!DOCTYPE html>
<html class="no-js" lang="de">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=2">
    <meta data-rh="true" property="og:type" content="product"/><meta data-rh="true" property="og:title" content="Funko POP! Pokémon Aquana Vinyl - GAMESHOP Marli"/><meta data-rh="true" property="og:url" content="https://www.gameshop-marli.de/p/funko-pop-pokemon-aquana-vinyl"/><meta data-rh="true" property="og:image" content="https://www.gameshop-marli.de/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512"/><meta data-rh="true" property="og:image:width" content="1000"/><meta data-rh="true" property="og:image:height" content="800"/><meta data-rh="true" property="og:price:amount" content="13.99"/><meta data-rh="true" property="og:price:currency" content="EUR"/><meta data-rh="true" name="description" content="Aus Funkos beliebter &#x27;POP!&#x27;-Reihe kommt diese coole Vinyl-Figur. Sie ist ca. 9 cm groß und wird in einer Fensterbox geliefert."/><meta data-rh="true" property="og:description" content="Aus Funkos beliebter &#x27;POP!&#x27;-Reihe kommt diese coole Vinyl-Figur. Sie ist ca. 9 cm groß und wird in einer Fensterbox geliefert."/>
    <title data-rh="true">Funko POP! Pokémon Aquana Vinyl - GAMESHOP Marli</title>
    <link rel="preload" href="/static/assets/oswald-v24-latin_cyrillic-regular-0aa64696cb06037f6f08.woff2" as="font" type="font/woff2" crossorigin="anonymous"/><link rel="preload" href="/static/assets/oswald-v24-latin_cyrillic-700-b9997837d0e584da3f67.woff2" as="font" type="font/woff2" crossorigin="anonymous"/>
    <script nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz">(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
              (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
              m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
              })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
              ga('create','UA-79023406-1','auto');
              ga('set','anonymizeIp',true);</script>
    <link data-chunk="app" rel="stylesheet" href="/static/app-74bf1fed557a9ddeb7b2.css"><link data-rh="true" rel="shortcut icon" href="/WebRoot/Store29/Shops/85205512/favicon.ico" type="image/x-icon"/><link data-rh="true" rel="stylesheet" id="themeStylesheet" href="/themes/epages.limelight/stylesheets/current.css?settings=%7B%22colors%22%3A%7B%22primaryColor%22%3A%22hsl(205%2C%20100%25%2C%2024%25)%22%2C%22headerBackground%22%3A%22hsl(57%2C%20100%25%2C%2071.8%25)%22%2C%22footerColor%22%3A%22hsl(326%2C%2098%25%2C%2033.3%25)%22%7D%2C%22fonts%22%3A%7B%22headingFont%22%3A%22Oswald%2Csans-serif%22%2C%22textFont%22%3A%22Oswald%2Csans-serif%22%7D%2C%22customStyle%22%3A%7B%22customCss%22%3A%22%22%7D%2C%22logoAdjustments%22%3A%7B%22alignment%22%3A%22center%22%2C%22spacing%22%3A9%2C%22sizing%22%3A119%7D%2C%22themeHeader%22%3A%7B%22headerType%22%3A%22oneRow%22%7D%7D"/>
    <script src="/static/start-ee6a7a1f0403b0a8813a.js" nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script><script data-chunk="app" src="/static/vendor-8eb303bee50da1762e97.js" type="module" nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script>
    <script data-chunk="app" src="/static/app-45ea8c8f459e7607c8d1.js" type="module" nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script>
    <script data-chunk="Product" src="/static/Product-d162cf57b1e0bb6daaf5.js" type="module" nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script>
    <script src="/epages/85205512.sf?ViewAction=UnityViewRegisterSessionScript" defer nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script><script src="/epages/85205512.sf?ViewAction=UnityViewFacebookBusinessPixelCode" defer nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script><script src="/epages/85205512.sf?ViewAction=UnityViewAddToWishlistScript" defer nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz"></script>
  </head>
  <body>
    
    <div id="app"><div class="ep-storefront-wrapper"><div class="react-progress-bar react-progress-bar-hide"><div class="react-progress-bar-percent" style="width:0%"></div><div class="react-progress-bar-spinner react-progress-bar-spinner-left"><div class="react-progress-bar-spinner-icon"></div></div></div><div class="body header-type-one-row"><div class="container"><section class="section section-usp"><div class="wrapper"><div><div class="header-usp mobile-view"><div><div class="swiper-container"><ul class="swiper-wrapper header-usp-list"><li class="swiper-slide header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-phone-icon"></span>0451 6132952<span></span></span></li><li class="swiper-slide header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-whatsapp-icon"></span>01520 6676745 <span></span></span></li><li class="swiper-slide header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-map-marker-icon"></span>Moislinger Allee 14, 23558 Lübeck<span></span></span></li><li class="swiper-slide header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-clock-01-icon"></span>Montag bis Donnerstag:: 10:00 – 18:00 Uhr<span></span></span></li><li class="swiper-slide header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-clock-01-icon"></span>Freitag &amp; Samstag: 10:00 – 19:00 Uhr<span></span></span></li></ul></div><div class="swiper-arrows"><div class="swiper-arrow-right"></div><div class="swiper-arrow-left swiper-button-disabled"></div></div></div></div><div class="header-usp desktop-view"><ul class="header-usp-list"><li class="header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-phone-icon"></span>0451 6132952</span></li><li class="header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-whatsapp-icon"></span>01520 6676745 </span></li><li class="header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-map-marker-icon"></span>Moislinger Allee 14, 23558 Lübeck</span></li><li class="header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-clock-01-icon"></span>Montag bis Donnerstag:: 10:00 – 18:00 Uhr</span></li><li class="header-usp-list-item"><span class="header-usp-list-item-wrapper"><span class="usp-clock-01-icon"></span>Freitag &amp; Samstag: 10:00 – 19:00 Uhr</span></li></ul></div></div></div></section><div class="page-canvas"><div class="section site-header"><div class="wrapper"><header class="header"><div class="block left"><nav role="navigation"><div class="navigation-overlay"><div class="toggle-menu"><button class="burger-icon" aria-label="Hauptmenü öffnen" aria-controls="main-menu-offcanvas" aria-expanded="false"><span class="burger-icon-stripes"></span></button></div><div id="main-menu-offcanvas" style="visibility:hidden"><div class="main-menu-overlay"></div><div class="main-menu-wrapper"><div class="main-menu-header"></div><ul class="main-menu"><li class=""><a href="/">GAMESHOP MARLI</a></li><li class=""><a href="/c/bald-erhaeltlich">BALD ERHÄLTLICH</a></li><li class=""><a href="/c/neuheiten">NEUHEITEN</a></li><li class=""><a href="/c/pokemon-store">Pokémon Store</a></li><li class=""><a href="/c/pokemon-karmesin-und-pokemon-purpur">Pokémon Karmesin und Pokémon Purpur</a></li><li class=""><a href="/c/sammelkarten">SAMMELKARTEN</a></li><li class=""><a href="/c/games-and-konsolen">GAMES &amp; KONSOLEN</a></li><li class=""><a href="/c/fan-artikel">FAN - ARTIKEL</a></li><li class=""><a href="/i/unser-geschaeft">UNSER GESCHÄFT</a></li><li class=""><a href="/i/kontakt">KONTAKT</a></li><li class=""><a href="/i/yu-gi-oh-turniere">Yu-Gi-Oh! Turniere</a></li><li class=""><a href="/i/tcg-veranstaltungen">TCG  Veranstaltungen</a></li><li class=""><a href="/i/gameshop-marli-club">GAMESHOP MARLI Club</a></li></ul></div></div></div></nav></div><div class="header-logo header-logo-adjustments"><a title="GAMESHOP Marli" class="header-logo-link" href="/"><img src="/storage/images/20th_logo_GAMESHOP_BIG.png?hash=7aac6dd1191e7ddd81e9fc5a89350139ed67357f&amp;shop=85205512" srcSet="/storage/images/20th_logo_GAMESHOP_BIG.png?hash=7aac6dd1191e7ddd81e9fc5a89350139ed67357f&amp;height=200&amp;width=2560&amp;shop=85205512 1x, /storage/images/20th_logo_GAMESHOP_BIG.png?hash=7aac6dd1191e7ddd81e9fc5a89350139ed67357f&amp;height=400&amp;width=2560&amp;shop=85205512 2x" alt="GAMESHOP Marli"/></a></div><div class="block right"><div class="header-search"><form tabindex="-1" autoComplete="off" action="/search" class="search-form"><button type="submit" class="search-form-icon search-form-submit"><span>Suche</span></button><input type="text" name="q" maxLength="200" value="" class="search-form-field" placeholder="Suche..."/></form></div><div class="header-account"><a href="/epages/85205512.sf/?ViewAction=UnityViewMyAccount&amp;Locale=de_DE" class="header-account-login" aria-label="Optionen für Ihr Kundenkonto"><span class="header-account-icon"></span></a></div><div class="header-minicart"><a class="header-minicart-checkout" href="/cart"><span class="visually-hidden">Warenkorb anzeigen. Sie haben einen Artikel im Warenkorb.<!-- --> </span><span class="header-minicart-icon" aria-hidden="true"></span><span class="header-minicart-badge" aria-hidden="true">1</span></a></div></div></header></div></div><main class="main"><span itemscope="" itemType="http://schema.org/BreadcrumbList"><span itemProp="itemListElement" itemscope="" itemType="http://schema.org/ListItem"><link href="/" itemProp="item"/><meta itemProp="name" content="GAMESHOP MARLI"/><meta itemProp="position" content="1"/></span><span itemProp="itemListElement" itemscope="" itemType="http://schema.org/ListItem"><link href="/p/funko-pop-pokemon-aquana-vinyl" itemProp="item"/><meta itemProp="name" content="Funko POP! Pokémon Aquana Vinyl"/><meta itemProp="position" content="2"/></span></span><div class="product" itemscope="" itemType="http://schema.org/Product"><meta itemProp="sku" content="7.74.581"/><meta itemProp="gtin13" content="0889698636971"/><section class="section"><div class="wrapper"><ul itemscope="" itemType="http://schema.org/BreadcrumbList" class="breadcrumb"><li itemProp="itemListElement" itemscope="" itemType="http://schema.org/ListItem"><a itemProp="item" href="/"><span itemProp="name">GAMESHOP MARLI</span></a><meta itemProp="position" content="1"/></li><li itemProp="itemListElement" itemscope="" itemType="http://schema.org/ListItem"><a itemProp="item" href="/p/funko-pop-pokemon-aquana-vinyl"><span itemProp="name">Funko POP! Pokémon Aquana Vinyl</span></a><meta itemProp="position" content="2"/></li></ul></div></section><section class="section"><div class="wrapper"><div class="content"><div class="product-image-gallery-wrapper"><div class="product-image-gallery"><div class="product-image-gallery-zoom-container"><div id="product-image-gallery-zoom"></div></div><div><div class="swiper-image-aspect-ratio"><div class="swiper-container swiper-main-image"><div class="swiper-wrapper"><div class="swiper-slide"><div class="ep-zoomable-image" style="--small-image-height:100%;pointer-events:none"><div class="image-magnify"><img class="image-magnify-small" style="max-width:1000px" src="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=600&amp;height=2560" srcSet="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=180&amp;height=2560 180w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=360&amp;height=2560 360w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=540&amp;height=2560 540w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=720&amp;height=2560 720w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=900&amp;height=2560 900w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=1000&amp;height=2560 1000w" sizes="0px" alt="Funko POP! Pokémon Aquana Vinyl"/></div></div><noscript><img src="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=600&amp;height=2560" style="max-width:1000px" itemProp="image"/></noscript></div><div class="swiper-slide"><div class="ep-zoomable-image" style="--small-image-height:100%;pointer-events:none"><div class="image-magnify"><img class="image-magnify-small" style="max-width:800px" src="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=600&amp;height=2560" srcSet="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=180&amp;height=2560 180w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=360&amp;height=2560 360w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=540&amp;height=2560 540w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=720&amp;height=2560 720w,/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=800&amp;height=2560 800w" sizes="0px" alt="Funko POP! Pokémon Aquana Vinyl"/></div></div><noscript><img src="/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=600&amp;height=2560" style="max-width:800px" itemProp="image"/></noscript></div></div></div></div><div class="product-image-gallery-bullets"><div class="product-image-gallery-bullet active"></div><div class="product-image-gallery-bullet"></div></div><div class="swiper-arrows"><div class="swiper-arrow-right"></div><div class="swiper-arrow-left swiper-button-disabled"></div></div><div class="product-image-gallery-thumbnails"><div class="product-image-gallery-thumbnail-outer active"><div class="product-image-gallery-thumbnail-inner" style="background-image:url(&quot;/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&quot;)"></div></div><div class="product-image-gallery-thumbnail-outer"><div class="product-image-gallery-thumbnail-inner" style="background-image:url(&quot;/storage/images/image?remote=https%3A%2F%2Fwww.gameshop-marli.de%2FWebRoot%2FStore29%2FShops%2F85205512%2F62B3%2F022D%2F345F%2FB14C%2F5B65%2F0A0C%2F6D10%2FAD8B%2FPOP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&quot;)"></div></div></div></div></div></div><div class="product-info"><h1 class="product-info-title" itemProp="name">Funko POP! Pokémon Aquana Vinyl</h1><div class="product-info-box"><div itemscope="" itemProp="offers" itemType="http://schema.org/Offer"><meta itemProp="url" content="/p/funko-pop-pokemon-aquana-vinyl"/><meta itemProp="price" content="13.99"/><meta itemProp="priceCurrency" content="EUR"/><link itemProp="availability" href="http://schema.org/InStock"/><link itemProp="itemCondition" href="http://schema.org/NewCondition"/></div><h3 class="product-info-box-price-single">13,99 €</h3><div class="product-info-box-wrapper"><div class="product-info-box-vat-note">inkl. MwSt.,<a class="product-info-box-shipping-link" href="/l/shipping"> <!-- -->zzgl. Versand</a></div></div><div id="ep-app-area-product-view-price"></div></div><div class="product-info-buybox"><div class="product-availability show-stock-level"><span class="product-availability-icon in-stock-icon"></span><span class="product-availability-info">Auf Lager</span></div><span class="product-delivery">Lieferzeit: 1 bis 4 Tag(e)</span><label for="quantity" class="product-quantity-field-label"><span>Menge:</span><div class="product-quantity-field"><button></button><input type="tel" id="quantity" min="1" value="1" autoComplete="off"/><button></button></div></label><div class="product-button-container"><button class="product-add-cart-button" type="button">In den Warenkorb</button><button class="product-add-wishlist-link" type="button">Zur Wunschliste hinzufügen</button></div></div><div class="product-addition"><h2 class="product-addition-headline">Beschreibung</h2><div class="product-addition-content" itemProp="description"><h2><strong>Funko POP!</strong><span> 627</span> <strong>Pokémon Aquana</strong></h2><p><br /></p><p> <span>POP! Vinyl von Funko. Die Figur ist 9 cm groß und wird in einer Schaufensterbox geliefert. Schauen Sie sich auch die anderen Funko-Figuren an, die dieser Sammlung gewidmet sind. Sammle sie alle!</span> </p><p><br /></p><p>Altersempfehlung ab 6 Jahre </p><p><br /></p></div></div></div></div></div></section></div></main><footer class="section site-footer"><div class="wrapper"><div class="footer"><ul class="pages"><li class="pages-item"><a class="pages-item-link" href="/l/contact">Impressum</a></li><li class="pages-item"><a class="pages-item-link" href="/l/privacy">Datenschutzerklärung</a></li><li class="pages-item"><a class="pages-item-link" href="/l/shipping">Zahlung &amp; Versand</a></li><li class="pages-item"><a class="pages-item-link" href="/l/tac">Allgemeine Geschäftsbedingungen</a></li><li class="pages-item"><a class="pages-item-link" href="/l/withdrawal">Widerrufsrecht</a></li></ul><div class="block"><ul class="social-media"><li class="social-media-icon"><a href="https://www.instagram.com/gameshop_marli/?hl=de" target="_blank" rel="noopener noreferrer" aria-label="Instagram"><span class="social-media-instagram" aria-hidden="true"></span></a></li><li class="social-media-icon"><a href="https://www.facebook.com/MendelGamesTeam/" target="_blank" rel="noopener noreferrer" aria-label="Facebook"><span class="social-media-facebook" aria-hidden="true"></span></a></li><li class="social-media-icon"><a href="https://www.youtube.com/results?search_query=gameshop+marli" target="_blank" rel="noopener noreferrer" aria-label="Youtube"><span class="social-media-youtube" aria-hidden="true"></span></a></li></ul></div><div class="block"></div><div class="providers"><ul class="payments"><li class="payments-item"><div class="payments-item-box"><img class="lazyload payments-item-box-logo" data-src="/themes/epages.base/assets/payments/pay-in-advance-f6fe942eae9f60bddf7d.svg" alt="Vorkasse" decoding="async" title="Vorkasse"/><noscript><img class="payments-item-box-logo" src="/themes/epages.base/assets/payments/pay-in-advance-f6fe942eae9f60bddf7d.svg" alt="Vorkasse" title="Vorkasse"/></noscript></div></li><li class="payments-item"><div class="payments-item-box"><img class="lazyload payments-item-box-logo" data-src="/themes/epages.base/assets/payments/paypal-5a7772a557b8329bccd3.svg" alt="PayPal" decoding="async" title="PayPal"/><noscript><img class="payments-item-box-logo" src="/themes/epages.base/assets/payments/paypal-5a7772a557b8329bccd3.svg" alt="PayPal" title="PayPal"/></noscript></div></li><li class="payments-item"><div class="payments-item-box"><img class="lazyload payments-item-box-logo" data-src="/storage/images/de-pp_plus-logo-quer_mit_PUI_540x60px.png?hash=b6adee9ffaca45fd6092fae2d7129314710f39e7&amp;shop=85205512" data-srcset="/storage/images/de-pp_plus-logo-quer_mit_PUI_540x60px.png?hash=b6adee9ffaca45fd6092fae2d7129314710f39e7&amp;shop=85205512&amp;height=22 1x, /storage/images/de-pp_plus-logo-quer_mit_PUI_540x60px.png?hash=b6adee9ffaca45fd6092fae2d7129314710f39e7&amp;shop=85205512&amp;height=44 2x" alt="PayPal Plus" decoding="async" title="PayPal Plus"/><noscript><img class="payments-item-box-logo" src="/storage/images/de-pp_plus-logo-quer_mit_PUI_540x60px.png?hash=b6adee9ffaca45fd6092fae2d7129314710f39e7&amp;shop=85205512&amp;width=600&amp;height=2560" alt="PayPal Plus" title="PayPal Plus"/></noscript></div></li></ul><ul class="logistics"><li class="logistics-item"><div class="logistics-item-box"><img class="lazyload logistics-item-box-logo" data-src="/themes/epages.base/assets/logistics/dhl-logo-418dd7caa4dbc9b3d077.svg" alt="DHL" decoding="async" title="DHL"/><noscript><img class="logistics-item-box-logo" src="/themes/epages.base/assets/logistics/dhl-logo-418dd7caa4dbc9b3d077.svg" alt="DHL" title="DHL"/></noscript></div></li></ul></div></div></div></footer></div></div><div class="add-to-cart-notice add-to-cart-notice-hidden"><div class="add-to-cart-notice-wrapper"><span class="add-to-cart-notice-close" title="Schließen"></span></div></div></div></div><div class="ep-alert-overlay"></div></div>
<script nonce="YzU0NzA0MmQtNjk4Yi00ODU4LTk5MjUtNmU2Y2M0MGEzNGEz">
window.__EP = {
shopSlug: '85205512',
storeInitialState: "{\"cart\":{\"pickupLineItem\":null,\"grandAmount\":\"18,99 \u20AC\",\"taxType\":\"GROSS\",\"coupon\":null,\"shippingAddress\":null,\",\"totalBasketDiscount\":null,\"checkoutState\":{\"readyToOrder\":null,\"shippingMethodValid\":null,\"pickupOptionValid\":null,\"paymentMethodValid\":null,\"billingAddressSet\":null,\"priceValidToOrder\":true,\"paymentTransactionStatus\":null},\"paymentLineItem\":{\"lineItemPrice\":{\"taxType\":\"GROSS\",\"formatted\":\"0,00 \u20AC\",\"amount\":0,\"currency\":\"EUR\"},\"paymentMethod\":{\"_id\":null,\"name\":\"PayPal\",\"description\":\"\"}},\"potentialBasketDiscounts\":null,\"minimumOrderValue\":null,\"status\":null,\"netAmount\":\"15,96 \u20AC\",\"shippingLineItem\":{\"lineItemPrice\":{\"taxType\":\"GROSS\",\"formatted\":\"5,00 \u20AC\",\"amount\":5,\"currency\":\"EUR\"},\"shippingMethod\":{\"_id\":null,\"name\":\"Versand innerhalb Deutschland\",\"description\":\"\"}},\"grandAmountNote\":\"views.storefrontView.basketPageSection.priceInclusiveVat\",\"couponCampaign\":null,\"grandTotal\":{\"taxType\":\"GROSS\",\"formatted\":\"18,99 \u20AC\",\"amount\":18.99,\"currency\":\"EUR\"},\"subAmount\":\"13,99 \u20AC\",\"billingAddress\":null,\"taxes\":[],\"subAmountValue\":13.99,\"cartValidation\":{\"possibleShippingMethods\":[\"Versand innerhalb Deutschland\",\"Click and Collect\"]},\"mustAcceptTermsAndConditions\":false,\"_links\":null,\"cartId\":\"630201B4-FB24-C1C1-0802-0A0C6D0B91A3\",\"checkoutButtons\":[],\\"totalNumberOfItems\":1,\"productLineItems\":[{\"productUrl\":\"/p/funko-pop-pokemon-aquana-vinyl\",\"lineItemPrice\":{\"taxType\":\"GROSS\",\"formatted\":\"13,99 \u20AC\",\"amount\":13.99,\"currency\":\"EUR\"},\"lineItemId\":\"630201B4-F208-1FD0-970B-0A0C6D0B9101\",\"energyLabelSourceFile\":null,\"variationString\":null,\"additionalInformation\":{\"bulkPriceInfo\":null},\"productId\":\"62B3022D-345F-B14C-5B65-0A0C6D10AD8B\",\"quantity\":1,\"essentialFeatures\":[],\"name\":\"Funko POP! Pok\u00E9mon Aquana Vinyl\",\"slug\":\"funko-pop-pokemon-aquana-vinyl\",\"listPrice\":{\"taxType\":\"GROSS\",\"formatted\":\"13,99 \u20AC\",\"amount\":13.99,\"currency\":\"EUR\"}
}
</script>
</body></html>

This is what i am trying to access: Specifically the lineItem ID

"productLineItems\":[{\"productUrl\":\"/p/funko-pop-pokemon-aquana-vinyl\",\"lineItemPrice\":{\"taxType\":\"GROSS\",\"formatted\":\"13,99 \u20AC\",\"amount\":13.99,\"currency\":\"EUR\"},\"lineItemId\":\"630201B4-F208-1FD0-970B-0A0C6D0B9101\"

This is my approach:

nonce = BeautifulSoup(response.text, "html.parser").find("script")["nonce"]
html = BeautifulSoup(response.text, "html.parser").findAll("script", {"nonce":nonce})[6]
info = html.select_one("script", string = re.compile("productLineItems"))
json_obj = json.loads(html.text.split("window.__EP =")[1].split(";")[0])
print(json_obj)

When I print html i get the correct section of the html unfortuantley I cant filter the JSON out :( and I have absolutley no idea what i did wrong.

Upvotes: 2

Views: 90

Answers (2)

threadfin
threadfin

Reputation: 163

There could be more than 1 lineItemId, so you could use re.findall() to get a list of them. If html is the correct section, you could do this:

import re
result = re.findall('"lineItemId":"([0-9A-Z\-]+)"', html)

where result is a list:

['630201B4-F208-1FD0-970B-0A0C6D0B9101']

Upvotes: 1

Daniil Fajnberg
Daniil Fajnberg

Reputation: 18663

As far as I can see, your supposed JSON string is not even valid JSON. But that is beside the point.

If all you are interested in, is the value of the lineItemId key in that JSON string, you don't need BeautifulSoup for parsing the entire HTML document and you don't need the JSON parser. A plain old RegEx should be enough:

import re

...

match = re.search(r'"lineItemId":\s*"([\w\-]+)"', response.text)
line_item_id = match.group(1)
print(line_item_id)

Output: 630201B4-F208-1FD0-970B-0A0C6D0B9101

This of course assumes that lineItemId occurs only once with that specific pattern in your HTML document.

Upvotes: 0

Related Questions