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

Time:08-21

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  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://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_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={"colors":{"primaryColor":"hsl(205, 100%, 24%)","headerBackground":"hsl(57, 100%, 71.8%)","footerColor":"hsl(326, 98%, 33.3%)"},"fonts":{"headingFont":"Oswald,sans-serif","textFont":"Oswald,sans-serif"},"customStyle":{"customCss":""},"logoAdjustments":{"alignment":"center","spacing":9,"sizing":119},"themeHeader":{"headerType":"oneRow"}}"/>
    <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 ><div ><div  style="width:0%"></div><div ><div ></div></div></div><div ><div ><section ><div ><div><div ><div><div ><ul ><li ><span ><span ></span>0451 6132952<span></span></span></li><li ><span ><span ></span>01520 6676745 <span></span></span></li><li ><span ><span ></span>Moislinger Allee 14, 23558 Lübeck<span></span></span></li><li ><span ><span ></span>Montag bis Donnerstag:: 10:00 – 18:00 Uhr<span></span></span></li><li ><span ><span ></span>Freitag &amp; Samstag: 10:00 – 19:00 Uhr<span></span></span></li></ul></div><div ><div ></div><div ></div></div></div></div><div ><ul ><li ><span ><span ></span>0451 6132952</span></li><li ><span ><span ></span>01520 6676745 </span></li><li ><span ><span ></span>Moislinger Allee 14, 23558 Lübeck</span></li><li ><span ><span ></span>Montag bis Donnerstag:: 10:00 – 18:00 Uhr</span></li><li ><span ><span ></span>Freitag &amp; Samstag: 10:00 – 19:00 Uhr</span></li></ul></div></div></div></section><div ><div ><div ><header ><div ><nav role="navigation"><div ><div ><button  aria-label="Hauptmenü öffnen" aria-controls="main-menu-offcanvas" aria-expanded="false"><span ></span></button></div><div id="main-menu-offcanvas" style="visibility:hidden"><div ></div><div ><div ></div><ul ><li ><a href="/">GAMESHOP MARLI</a></li><li ><a href="/c/bald-erhaeltlich">BALD ERHÄLTLICH</a></li><li ><a href="/c/neuheiten">NEUHEITEN</a></li><li ><a href="/c/pokemon-store">Pokémon Store</a></li><li ><a href="/c/pokemon-karmesin-und-pokemon-purpur">Pokémon Karmesin und Pokémon Purpur</a></li><li ><a href="/c/sammelkarten">SAMMELKARTEN</a></li><li ><a href="/c/games-and-konsolen">GAMES &amp; KONSOLEN</a></li><li ><a href="/c/fan-artikel">FAN - ARTIKEL</a></li><li ><a href="/i/unser-geschaeft">UNSER GESCHÄFT</a></li><li ><a href="/i/kontakt">KONTAKT</a></li><li ><a href="/i/yu-gi-oh-turniere">Yu-Gi-Oh! Turniere</a></li><li ><a href="/i/tcg-veranstaltungen">TCG  Veranstaltungen</a></li><li ><a href="/i/gameshop-marli-club">GAMESHOP MARLI Club</a></li></ul></div></div></div></nav></div><div ><a title="GAMESHOP Marli"  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 ><div ><form tabindex="-1" autoComplete="off" action="/search" ><button type="submit" ><span>Suche</span></button><input type="text" name="q" maxLength="200" value=""  placeholder="Suche..."/></form></div><div ><a href="/epages/85205512.sf/?ViewAction=UnityViewMyAccount&amp;Locale=de_DE"  aria-label="Optionen für Ihr Kundenkonto"><span ></span></a></div><div ><a  href="/cart"><span >Warenkorb anzeigen. Sie haben einen Artikel im Warenkorb.<!-- --> </span><span  aria-hidden="true"></span><span  aria-hidden="true">1</span></a></div></div></header></div></div><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  itemscope="" itemType="http://schema.org/Product"><meta itemProp="sku" content="7.74.581"/><meta itemProp="gtin13" content="0889698636971"/><section ><div ><ul itemscope="" itemType="http://schema.org/BreadcrumbList" ><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 ><div ><div ><div ><div ><div ><div id="product-image-gallery-zoom"></div></div><div><div ><div ><div ><div ><div  style="--small-image-height:100%;pointer-events:none"><div ><img  style="max-width:1000px" src="/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=600&amp;height=2560" srcSet="/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=180&amp;height=2560 180w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=360&amp;height=2560 360w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=540&amp;height=2560 540w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=720&amp;height=2560 720w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=900&amp;height=2560 900w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_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://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&amp;width=600&amp;height=2560" style="max-width:1000px" itemProp="image"/></noscript></div><div ><div  style="--small-image-height:100%;pointer-events:none"><div ><img  style="max-width:800px" src="/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=600&amp;height=2560" srcSet="/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=180&amp;height=2560 180w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=360&amp;height=2560 360w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=540&amp;height=2560 540w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&amp;width=720&amp;height=2560 720w,/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_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://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_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 ><div ></div><div ></div></div><div ><div ></div><div ></div></div><div ><div ><div  style="background-image:url(&quot;/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_00.png&amp;shop=85205512&quot;)"></div></div><div ><div  style="background-image:url(&quot;/storage/images/image?remote=https://www.gameshop-marli.de/WebRoot/Store29/Shops/85205512/62B3/022D/345F/B14C/5B65/0A0C/6D10/AD8B/POP_-_Pokemon_-_Vaporeon_01.png&amp;shop=85205512&quot;)"></div></div></div></div></div></div><div ><h1  itemProp="name">Funko POP! Pokémon Aquana Vinyl</h1><div ><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 >13,99 €</h3><div ><div >inkl. MwSt.,<a  href="/l/shipping"> <!-- -->zzgl. Versand</a></div></div><div id="ep-app-area-product-view-price"></div></div><div ><div ><span ></span><span >Auf Lager</span></div><span >Lieferzeit: 1 bis 4 Tag(e)</span><label for="quantity" ><span>Menge:</span><div ><button></button><input type="tel" id="quantity" min="1" value="1" autoComplete="off"/><button></button></div></label><div ><button  type="button">In den Warenkorb</button><button  type="button">Zur Wunschliste hinzufügen</button></div></div><div ><h2 >Beschreibung</h2><div  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 ><div ><div ><ul ><li ><a  href="/l/contact">Impressum</a></li><li ><a  href="/l/privacy">Datenschutzerklärung</a></li><li ><a  href="/l/shipping">Zahlung &amp; Versand</a></li><li ><a  href="/l/tac">Allgemeine Geschäftsbedingungen</a></li><li ><a  href="/l/withdrawal">Widerrufsrecht</a></li></ul><div ><ul ><li ><a href="https://www.instagram.com/gameshop_marli/?hl=de" target="_blank" rel="noopener noreferrer" aria-label="Instagram"><span  aria-hidden="true"></span></a></li><li ><a href="https://www.facebook.com/MendelGamesTeam/" target="_blank" rel="noopener noreferrer" aria-label="Facebook"><span  aria-hidden="true"></span></a></li><li ><a href="https://www.youtube.com/results?search_query=gameshop marli" target="_blank" rel="noopener noreferrer" aria-label="Youtube"><span  aria-hidden="true"></span></a></li></ul></div><div ></div><div ><ul ><li ><div ><img  data-src="/themes/epages.base/assets/payments/pay-in-advance-f6fe942eae9f60bddf7d.svg" alt="Vorkasse" decoding="async" title="Vorkasse"/><noscript><img  src="/themes/epages.base/assets/payments/pay-in-advance-f6fe942eae9f60bddf7d.svg" alt="Vorkasse" title="Vorkasse"/></noscript></div></li><li ><div ><img  data-src="/themes/epages.base/assets/payments/paypal-5a7772a557b8329bccd3.svg" alt="PayPal" decoding="async" title="PayPal"/><noscript><img  src="/themes/epages.base/assets/payments/paypal-5a7772a557b8329bccd3.svg" alt="PayPal" title="PayPal"/></noscript></div></li><li ><div ><img  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  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 ><li ><div ><img  data-src="/themes/epages.base/assets/logistics/dhl-logo-418dd7caa4dbc9b3d077.svg" alt="DHL" decoding="async" title="DHL"/><noscript><img  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 ><div ><span  title="Schließen"></span></div></div></div></div><div ></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.

CodePudding user response:

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.

CodePudding user response:

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']
  • Related