如何使用Beautiful Soup来<script>标签?

时间:2019-12-02 07:50:58

标签: python beautifulsoup

在给定的.html页面中,我有一个脚本标签,如下所示:

<script type="application/javascript">
        window.__PRODUCT_DETAIL_APP_INITIAL_STATE__ = {"product":{"attributes":[{"key":{"name":"Renk","id":348},"value":{"name":"Siyah","id":14}}],"variants":[{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"35,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"35-5","isWinner":false,"listingId":"6a09cee2ec51521012351a3cae581fd3","stock":2,"sellable":true,"availableForClaim":true,"barcode":"190510862165"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"36","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"36","isWinner":false,"listingId":"f927d969d0f4351df402d271008b093a","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862172"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"36,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"36-5","isWinner":false,"listingId":"2290fdf18ec4363b088b859a9ca05cf8","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862189"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"37,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"37-5","isWinner":false,"listingId":"93cde909de0155ddb4ed75dec1cc0924","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862196"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"38","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"38","isWinner":false,"listingId":"f44f564c25a978510e349af3ad806670","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862202"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"38,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"38-5","isWinner":false,"listingId":"6cdf921204cab20f4bc8df35cda149ec","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862219"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"39","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"39","isWinner":true,"listingId":"2554ec2671721b6b8a2cfc7cc33c6f9e","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862226"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"40","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"40","isWinner":false,"listingId":"622d3334418f07d86dc5f73af5c35bd9","stock":3,"sellable":true,"availableForClaim":true,"barcode":"190510862233"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"40,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"40-5","isWinner":false,"listingId":"6c63c9a7bfa3ce5063dfc20c15b5d7f5","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862240"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"41","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"41","isWinner":false,"listingId":"96d45c66361779f28aa2821a211186a5","stock":1,"sellable":true,"availableForClaim":true,"barcode":"190510862257"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"42","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"42","isWinner":false,"listingId":"31ed39f258950ca9d19f67a42cd61467","stock":1,"sellable":true,"availableForClaim":true,"barcode":"190510862264"}],"otherMerchants":[],"campaign":{"id":376097,"name":"Under Armour - Kadın & Erkek & Çocuk Spor Giyim","startDate":"2019-11-30T06:00:00","endDate":"2019-12-11T05:55:00","isMultipleSupplied":false,"stockTypeId":7,"url":"/under-armour---kadin--erkek--cocuk-spor-giyim/butikdetay/376097","showTimer":false},"category":{"id":101426,"name":"Koşu Ayakkabısı","hierarchy":"Ayakkabı/Spor Ayakkabı/Koşu & Antrenman Ayakkabısı","beautifiedName":"kosu-ayakkabisi"},"brand":{"id":104189,"name":"Under Armour","beautifiedName":"under-armour","isVirtual":true},"color":"002","showVariants":true,"id":6740744,"productCode":"1285482","name":"Kadın Koşu & Antrenman Ayakkabısı - UA W Speedform Europa - 1285482-002","description":"\u003cul>\u003cli>STABILITY: Ekstra kavrama ve yastıklama isteyen koşucular için\u003c/li>\u003cli>Yenilikçi UA SpeedForm yapısı ayağın şeklini alarak tam uyum sağlar ve dikkatin dağılmasını önler\u003c/li>\u003cli>Coreshort orta ayak panelleri mükemmel sabitlenme ve esnek destek sağlar\u003c/li>\u003cli>Dilde ve burunda kullanılan hafif file ayağın uyumunu ve havalandırmayı artırır\u003c/li>\u003cli>Ekstra destek ve yapı için dış TPU ökçe desteği\u003c/li>\u003cli>Ekstra tampon, destek ve dikişsiz konfor sağlayan tabanlık\u003c/li>\u003cli>Charged Cushioning orta taban daha fazla tepki ve dayanıklılık için sıkıştırılmış köpük kullanarak optimal destek ve enerji dönüşü sağlar\u003c/li>\u003cli>Micro G ökçe parçası ve orta direk korumayı ve dengeyi artırır\u003c/li>\u003cli>Çift yoğunluklu orta sütun aşırı içe bükülmeyi önlemeye yardımcı olur\u003c/li>\u003cli>Ön ayağın altındaki üflemeli kauçuk hafif fakat inanılmaz hassastır\u003c/li>\u003cli>Yerle temastan kaynaklanan titreşimi sönümlemek için topuğun altına yüksek aşınma oranına sahip kauçuk yerleştirilmiştir\u003c/li>\u003cli>Ofset: 8 mm\u003c/li>\u003cli>Ağırlık: 240 gram\u003c/li>\u003cli>Kampanya fiyatından satılmak üzere 10 adetten fazla stok sunulmuştur.\u003c/li>\u003cli>Ürün kartında gösterilen üstü çizili ilk fiyat tedarikçi tarafından beslenen perakende satış fiyatıdır.\u003c/li>\u003c/ul>","productGroupId":5771518,"tax":8,"businessUnit":"Sportswear","gender":{"name":"Kadın","id":1},"url":"/under-armour/kadin-kosu-antrenman-ayakkabisi-ua-w-speedform-europa-1285482-002-p-6740744?boutiqueId=376097&merchantId=109430","images":["/Assets/ProductImages/oa/47/6740744/2/190510862257_1_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_2_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_3_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_4_org_zoom.jpg"],"isSellable":true,"isBasketDiscount":false,"hasStock":true,"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"isFreeCargo":false,"promotions":[],"merchant":{"id":109430,"name":"Under Armour","officialName":"DOĞUŞ PERAKENDE SATIŞ GİY. VE AKS.TİC. A.Ş.(UNDER ARMOUR)","cityName":" İstanbul ","taxNumber":"3090344202","sellerScore":9.2},"deliveryInformation":{"isRushDelivery":false,"deliveryDate":"3 - 24 Aralık"},"isMarketplace":true,"productStamps":[],"hasHtmlContent":false,"favoriteCount":192,"uxLayout":"Fashion"},"reviews":{"contentSummary":{"ratingCounts":[],"userCommentExist":false,"averageRating":0,"totalCommentCount":0,"totalRatingCount":0},"productReviews":{"totalElements":0,"totalPages":0,"content":[],"userCommentExist":false},"productSummary":null},"htmlContent":null,"user":{"loggedIn":false,"id":0,"isBuyer":false},"configuration":{"htmlContentCssUrl":"https://static.dsmcdn.com/frontend/pim/rich-content/production/main.cf9ab001241f21c7ffef520f9487ab4d.css","htmlContentJsUrl":"https://static.dsmcdn.com/frontend/pim/rich-content/production/main.8050003e34b702b545d67ec9d05bf408.js","storefrontId":1,"culture":"tr-TR","cdnUrl":"https://img-trendyol.mncdn.com","claimInfoText":"15 gün içinde ücretsiz iade.","ratingReviewEnabled":true,"ratingReviewLikesEnabled":false,"languageCode":"tr","sizeCharts":[["Güneş Gözlüğü","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/gozluk_beden_tablosu.jpg","Gözlük Beden Kılavuzu"],["İmaj Gözlükleri","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/gozluk_beden_tablosu.jpg","Gözlük Beden Kılavuzu"],["Saat","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/saatler_beden_tablosu.jpg","Saat Beden Kılavuzu"]],"enhancedEcommerceEnabled":true,"sellerAreaAbTest":"1","addReviewEnabled":true,"reviewReportAbuseEnabled":true,"crossProductsTitle":"Bu Ürünü Alanlar Bunları da Aldı","crossProductsEnabled":true,"recommendationEnabled":true,"productGroupEnabled":true,"htmlContentEnabled":true,"sellerAreaEnabled":true,"sellerPointLowLimit":8,"sizeChartUrl":"https://img-trendyol.mncdn.com/Assets/frontend-web-sizechart/tr1.html","productDetailMetaDescription":"Trendyol.com sayesinde {0} ürününe çok özel indirimlerle sahip olabilecek ve alışveriş alışkanlıklarınızı değiştireceksiniz.","schemaJsonEnabled":false,"siteAddress":"https://www.trendyol.com","notifyMeEnabled":true,"notifyMeCount":10,"accountGwFavoritesEnabled":true,"browsingGwUrl":"https://api.trendyol.com/webbrowsinggw","recommendationAbTestValue":"A_0-0,B_0-0,C_1-100","abTestingCookieName":"WebAbTesting","clientSideReviewsEnabled":false,"clientSideHtmlContentEnabled":false,"apiExternalEnabled":true}};
      </script>

如何使用Beautiful Soup提取条形码编号? (“条形码”:“ 190510862189”})

2 个答案:

答案 0 :(得分:1)

使用正则表达式。

例如:

import re
import json
from bs4 import BeautifulSoup
html = """<script type="application/javascript">
        window.__PRODUCT_DETAIL_APP_INITIAL_STATE__ = {"product":{"attributes":[{"key":{"name":"Renk","id":348},"value":{"name":"Siyah","id":14}}],"variants":[{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"35,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"35-5","isWinner":false,"listingId":"6a09cee2ec51521012351a3cae581fd3","stock":2,"sellable":true,"availableForClaim":true,"barcode":"190510862165"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"36","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"36","isWinner":false,"listingId":"f927d969d0f4351df402d271008b093a","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862172"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"36,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"36-5","isWinner":false,"listingId":"2290fdf18ec4363b088b859a9ca05cf8","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862189"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"37,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"37-5","isWinner":false,"listingId":"93cde909de0155ddb4ed75dec1cc0924","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862196"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"38","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"38","isWinner":false,"listingId":"f44f564c25a978510e349af3ad806670","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862202"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"38,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"38-5","isWinner":false,"listingId":"6cdf921204cab20f4bc8df35cda149ec","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862219"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"39","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"39","isWinner":true,"listingId":"2554ec2671721b6b8a2cfc7cc33c6f9e","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862226"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"40","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"40","isWinner":false,"listingId":"622d3334418f07d86dc5f73af5c35bd9","stock":3,"sellable":true,"availableForClaim":true,"barcode":"190510862233"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"40,5","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"40-5","isWinner":false,"listingId":"6c63c9a7bfa3ce5063dfc20c15b5d7f5","stock":null,"sellable":true,"availableForClaim":true,"barcode":"190510862240"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"41","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"41","isWinner":false,"listingId":"96d45c66361779f28aa2821a211186a5","stock":1,"sellable":true,"availableForClaim":true,"barcode":"190510862257"},{"attributeId":338,"attributeName":"Beden","attributeType":"Size","attributeValue":"42","stamps":[{"type":3,"text":"%60"}],"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"attributeBeautifiedValue":"42","isWinner":false,"listingId":"31ed39f258950ca9d19f67a42cd61467","stock":1,"sellable":true,"availableForClaim":true,"barcode":"190510862264"}],"otherMerchants":[],"campaign":{"id":376097,"name":"Under Armour - Kadın & Erkek & Çocuk Spor Giyim","startDate":"2019-11-30T06:00:00","endDate":"2019-12-11T05:55:00","isMultipleSupplied":false,"stockTypeId":7,"url":"/under-armour---kadin--erkek--cocuk-spor-giyim/butikdetay/376097","showTimer":false},"category":{"id":101426,"name":"Koşu Ayakkabısı","hierarchy":"Ayakkabı/Spor Ayakkabı/Koşu & Antrenman Ayakkabısı","beautifiedName":"kosu-ayakkabisi"},"brand":{"id":104189,"name":"Under Armour","beautifiedName":"under-armour","isVirtual":true},"color":"002","showVariants":true,"id":6740744,"productCode":"1285482","name":"Kadın Koşu & Antrenman Ayakkabısı - UA W Speedform Europa - 1285482-002","description":"\u003cul>\u003cli>STABILITY: Ekstra kavrama ve yastıklama isteyen koşucular için\u003c/li>\u003cli>Yenilikçi UA SpeedForm yapısı ayağın şeklini alarak tam uyum sağlar ve dikkatin dağılmasını önler\u003c/li>\u003cli>Coreshort orta ayak panelleri mükemmel sabitlenme ve esnek destek sağlar\u003c/li>\u003cli>Dilde ve burunda kullanılan hafif file ayağın uyumunu ve havalandırmayı artırır\u003c/li>\u003cli>Ekstra destek ve yapı için dış TPU ökçe desteği\u003c/li>\u003cli>Ekstra tampon, destek ve dikişsiz konfor sağlayan tabanlık\u003c/li>\u003cli>Charged Cushioning orta taban daha fazla tepki ve dayanıklılık için sıkıştırılmış köpük kullanarak optimal destek ve enerji dönüşü sağlar\u003c/li>\u003cli>Micro G ökçe parçası ve orta direk korumayı ve dengeyi artırır\u003c/li>\u003cli>Çift yoğunluklu orta sütun aşırı içe bükülmeyi önlemeye yardımcı olur\u003c/li>\u003cli>Ön ayağın altındaki üflemeli kauçuk hafif fakat inanılmaz hassastır\u003c/li>\u003cli>Yerle temastan kaynaklanan titreşimi sönümlemek için topuğun altına yüksek aşınma oranına sahip kauçuk yerleştirilmiştir\u003c/li>\u003cli>Ofset: 8 mm\u003c/li>\u003cli>Ağırlık: 240 gram\u003c/li>\u003cli>Kampanya fiyatından satılmak üzere 10 adetten fazla stok sunulmuştur.\u003c/li>\u003cli>Ürün kartında gösterilen üstü çizili ilk fiyat tedarikçi tarafından beslenen perakende satış fiyatıdır.\u003c/li>\u003c/ul>","productGroupId":5771518,"tax":8,"businessUnit":"Sportswear","gender":{"name":"Kadın","id":1},"url":"/under-armour/kadin-kosu-antrenman-ayakkabisi-ua-w-speedform-europa-1285482-002-p-6740744?boutiqueId=376097&merchantId=109430","images":["/Assets/ProductImages/oa/47/6740744/2/190510862257_1_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_2_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_3_org_zoom.jpg","/Assets/ProductImages/oa/47/6740744/2/190510862257_4_org_zoom.jpg"],"isSellable":true,"isBasketDiscount":false,"hasStock":true,"price":{"profitMargin":2,"discountedPrice":{"text":"399,90 TL","value":399.9},"sellingPrice":{"text":"399,90 TL","value":399.9},"originalPrice":{"text":"999,90 TL","value":999.9},"currency":"TRY"},"isFreeCargo":false,"promotions":[],"merchant":{"id":109430,"name":"Under Armour","officialName":"DOĞUŞ PERAKENDE SATIŞ GİY. VE AKS.TİC. A.Ş.(UNDER ARMOUR)","cityName":" İstanbul ","taxNumber":"3090344202","sellerScore":9.2},"deliveryInformation":{"isRushDelivery":false,"deliveryDate":"3 - 24 Aralık"},"isMarketplace":true,"productStamps":[],"hasHtmlContent":false,"favoriteCount":192,"uxLayout":"Fashion"},"reviews":{"contentSummary":{"ratingCounts":[],"userCommentExist":false,"averageRating":0,"totalCommentCount":0,"totalRatingCount":0},"productReviews":{"totalElements":0,"totalPages":0,"content":[],"userCommentExist":false},"productSummary":null},"htmlContent":null,"user":{"loggedIn":false,"id":0,"isBuyer":false},"configuration":{"htmlContentCssUrl":"https://static.dsmcdn.com/frontend/pim/rich-content/production/main.cf9ab001241f21c7ffef520f9487ab4d.css","htmlContentJsUrl":"https://static.dsmcdn.com/frontend/pim/rich-content/production/main.8050003e34b702b545d67ec9d05bf408.js","storefrontId":1,"culture":"tr-TR","cdnUrl":"https://img-trendyol.mncdn.com","claimInfoText":"15 gün içinde ücretsiz iade.","ratingReviewEnabled":true,"ratingReviewLikesEnabled":false,"languageCode":"tr","sizeCharts":[["Güneş Gözlüğü","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/gozluk_beden_tablosu.jpg","Gözlük Beden Kılavuzu"],["İmaj Gözlükleri","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/gozluk_beden_tablosu.jpg","Gözlük Beden Kılavuzu"],["Saat","https://img-trendyol.mncdn.com/assets/banner/2018/webBanners/bedenTablosu/saatler_beden_tablosu.jpg","Saat Beden Kılavuzu"]],"enhancedEcommerceEnabled":true,"sellerAreaAbTest":"1","addReviewEnabled":true,"reviewReportAbuseEnabled":true,"crossProductsTitle":"Bu Ürünü Alanlar Bunları da Aldı","crossProductsEnabled":true,"recommendationEnabled":true,"productGroupEnabled":true,"htmlContentEnabled":true,"sellerAreaEnabled":true,"sellerPointLowLimit":8,"sizeChartUrl":"https://img-trendyol.mncdn.com/Assets/frontend-web-sizechart/tr1.html","productDetailMetaDescription":"Trendyol.com sayesinde {0} ürününe çok özel indirimlerle sahip olabilecek ve alışveriş alışkanlıklarınızı değiştireceksiniz.","schemaJsonEnabled":false,"siteAddress":"https://www.trendyol.com","notifyMeEnabled":true,"notifyMeCount":10,"accountGwFavoritesEnabled":true,"browsingGwUrl":"https://api.trendyol.com/webbrowsinggw","recommendationAbTestValue":"A_0-0,B_0-0,C_1-100","abTestingCookieName":"WebAbTesting","clientSideReviewsEnabled":false,"clientSideHtmlContentEnabled":false,"apiExternalEnabled":true}};
      </script>"""

soup = BeautifulSoup(html, "html.parser")
jstring = re.search(r"(?<=\=)(.*?)(?=\};)", soup.find('script').string).group(1)
data = json.loads(jstring + "}")
for elem in data['product']['variants']:
    print(elem['barcode'])

输出:

190510862165
190510862172
190510862189
190510862196
190510862202
190510862219
190510862226
190510862233
190510862240
190510862257
190510862264

答案 1 :(得分:0)

BeautifulSoup并非用于执行或解析JavaScript。

幸运的是,这些数据看起来像JSON。您可以在标签内容上使用RegEx来隔离数据,将其解析为JSON,然后访问所需的值。

相关问题