获取 GTIN使用正则表达式和/或 xpath |源代码" />

我需要提取GTIN值( 8806090325632 ) 我需要获取XPath表达式以刮擦13位GTIN代码。

这是< script type =“ application/ld+json”> 代码:

< script type =“ application/ld+json”> {“ @Type”:“ product”,“聚合”:{“@type”:“聚合”,“ cratingValue”:4.49469964646431095,“ cratingCount”:566,“ 566,” BESTRATING“品牌“:{”@type”:“组织”,“名称”:“ Samsung”},“描述”:“ Samsung 65TU7022电视LED 4K -65 \”(163cm) - HDR10 + -Dolby Digital Plus -Smart TV- 2xHdmi -1xusb -classeénergétiqueg“,“ gtin”:“ 8806090325632”,“ guert”:{“@type”:“ ovelobility”,“可用性”,“ instock”:“ instock”,“ instock”,“ itemcondition”,“ itemcondition”,“ newcondition”:“ newcondition”,“ newcondition”,“”,“ newcondition”,“”,“”,“”,“”,“”,“”,“” :615.99,“ PriceCurrency”:“ Eur”,“ PriceValiduntil”:“ 2022-04-04-06T14:57:01.7797852+02:00”,“ url”,“ url”:“ HTTPS:” Televiseurs/Samsung-65TU7022-TV-TV-4K-UHD-65-163-CM-H/F-1062613-SAMUE65TU7022.HTML?IDOFFRE = 639618765“},” LED”,“ SKU”:“ SAMUE65TU7022”,“评论”:[{“@type”:“评论”,“评论”:{“@type”:“评分”,“ Bestrating”,“ Bestrating”:“ 5”,“ ratingValue “:“ 5”,“ Worstrating”:“ 1”},“作者”:“ SOSO”,“ DatePubling”:“ 2022-04-04-03T03:54:10”,“ Descript”,“ Descript”:帕菲特“,”名称“:”帕法特“},{”@type“:”评论“,”审核``:{“@type”:“ rating”,“ bestrating”:“ bestrating”:“ 5”,“ cratingValue”:“ 4 “,“ worstrating”:“ 1”},“作者”:“ smashingquasar”,“ datePumined”:“ 2022-04-02T14:13:13:13:11”,“描述”:联合国大奖可分配。 laQualitéd'emimate Est recoresansêtreexceptionnelle。 Le hdr est anecdotique sur cemodèle,on ne le discerne presque pas。 4étoilespour cemodèle简单汽车la profondeur de noir estistisfaisante。 En Dehorsdeça,Une Assez Bonne Affaire Pour Ceux Qui Souhaitent Passeràla4k。 @Type“:”额定值“:bestrating”:“ 5”,“ conatingValue”:“ 5”,“ Worstrating”:“ 1”},“作者”:“ Luna”,“ datePubly”:“ 2022-04---” 01T07:40:28“,” description“:” Sa Taille等人选项SONT AU TOP…“,”名称“:” TRES BON CHOIX“},{“@type”:“评论”,“评论”,“ ReviewSrating”:{{{ @Type“:”额定值,“ bestrating”:“ 5”,“ ratingValue”:“ 4”,“ worstrating”:“ 1”},“作者”:“ sylva”,“ datePubly”:“ 2022-03-- 28T13:27:19“,“描述”:“ Je Viens d'Acheter CeTéléviseurMais Malheureusement Pas de Connection蓝牙。 S'il faille le Contacter Avec avec une barre de son bluetooth n'yrêvezMêmePas。一个部分。最好的“:” 5“,“ cantingValue”:“ 4”,“ worstrating”:“ 1”},“作者”:“ mortimer”,“ datePumined”:“ 2022-03-27T20:07:23Z”,“描述” “:“ l'image est superbe,pont - sesfinctionnalités,elles sont sont nombreuses que je je n'ai encore encore pas eu le temps de toutes de toutes les tester ...”,“ name”:“ une bellebête!” “ @context”:“ https://schema.org”,“ name”:“三星65TU7022电视LED LED 4K UHD -65 \”(163 cm) - HDR10 + -Dolby Digital Plus- -smart TV -2XHDMI -2XHDMI -1XHDMI -1xusb”, “图像”:“ https://www.cdiscount.com/pdt2/0/2/2/4/4/550x550/samue65tu70222/rw/samsung-65tu70222222-tv-led-4k-4k-uhd-4k-uhd-65-165-163-cm-h .jpg","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022 .html“}</script>

I need to extract the gtin value (8806090325632)
I need to get the xpath expression to scrape the 13 digit gtin code only.

Here is the <script type="application/ld+json"> code :

<script type="application/ld+json"> {"@type":"Product","aggregateRating":{"@type":"AggregateRating","ratingValue":4.4946996466431095,"ratingCount":566,"bestRating":5.0,"worstRating":1.0},"brand":{"@type":"Organization","name":"SAMSUNG"},"description":"SAMSUNG 65TU7022 TV LED 4K - 65 \" (163cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB - Classe énergétique G","gtin":"8806090325632","offers":{"@type":"Offer","availability":"InStock","itemCondition":"NewCondition","price":615.99,"priceCurrency":"EUR","priceValidUntil":"2022-04-06T14:57:01.7797852+02:00","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html?idOffre=639618765"},"productID":"SAMUE65TU7022","category":"Téléviseur LED","sku":"samue65tu7022","review":[{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"Soso","datePublished":"2022-04-03T03:54:10","description":"Je recommande cet achat tout est parfait","name":"Parfait"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"SmashingQuasar","datePublished":"2022-04-02T14:13:11","description":"Cette télévision est grande et offre une résolution 4K pour un prix abordable. La qualité d'image est correcte sans être exceptionnelle. Le HDR est anecdotique sur ce modèle, on ne le discerne presque pas. 4 étoiles pour ce modèle simplement car la profondeur de noir est insatisfaisante. En dehors de ça, une assez bonne affaire pour ceux qui souhaitent passer à la 4K.","name":"Une grande TV 4K peu chère"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"luna","datePublished":"2022-04-01T07:40:28","description":"Sa taille et les options sont au top…","name":"TRES BON CHOIX"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Sylva","datePublished":"2022-03-28T13:27:19","description":"Je viens d'acheter ce téléviseur mais malheureusement pas de connection Bluetooth possible. S'il faille le contacter avec avec une barre de son Bluetooth n'y rêvez même pas. A part ça tout est parfait pour l'instant","name":"Pas de connexion Bluetooth possible"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Mortimer","datePublished":"2022-03-27T20:07:23Z","description":"L'image est superbe, quant à ses fonctionnalités, elles sont tellement nombreuses que je n'ai encore pas eu le temps de toutes les tester...","name":"Une belle bête !"}],"@context":"https://schema.org","name":"SAMSUNG 65TU7022 TV LED 4K UHD - 65 \" (163 cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB","image":"https://www.cdiscount.com/pdt2/0/2/2/4/550x550/samue65tu7022/rw/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h.jpg","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html"}</script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2025-01-26 03:47:30

虽然没有提到明确的语言标签,但这个答案指出了使用 python 的方法。

从 HTML 中选择

data = json.loads(soup.select_one('script[type="application/ld+json"]').text)

现在您可以通过按键选择 GTIN:

data['gtin']

示例

html = r'''<script type="application/ld+json">{"@type":"Product","aggregateRating":{"@type":"AggregateRating","ratingValue":4.4946996466431095,"ratingCount":566,"bestRating":5.0,"worstRating":1.0},"brand":{"@type":"Organization","name":"SAMSUNG"},"description":"SAMSUNG 65TU7022 TV LED 4K - 65 \" (163cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB - Classe énergétique G","gtin":"8806090325632","offers":{"@type":"Offer","availability":"InStock","itemCondition":"NewCondition","price":615.99,"priceCurrency":"EUR","priceValidUntil":"2022-04-06T14:57:01.7797852+02:00","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html?idOffre=639618765"},"productID":"SAMUE65TU7022","category":"Téléviseur LED","sku":"samue65tu7022","review":[{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"Soso","datePublished":"2022-04-03T03:54:10","description":"Je recommande cet achat tout est parfait","name":"Parfait"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"SmashingQuasar","datePublished":"2022-04-02T14:13:11","description":"Cette télévision est grande et offre une résolution 4K pour un prix abordable. La qualité d'image est correcte sans être exceptionnelle. Le HDR est anecdotique sur ce modèle, on ne le discerne presque pas. 4 étoiles pour ce modèle simplement car la profondeur de noir est insatisfaisante. En dehors de ça, une assez bonne affaire pour ceux qui souhaitent passer à la 4K.","name":"Une grande TV 4K peu chère"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"luna","datePublished":"2022-04-01T07:40:28","description":"Sa taille et les options sont au top…","name":"TRES BON CHOIX"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Sylva","datePublished":"2022-03-28T13:27:19","description":"Je viens d'acheter ce téléviseur mais malheureusement pas de connection Bluetooth possible. S'il faille le contacter avec avec une barre de son Bluetooth n'y rêvez même pas. A part ça tout est parfait pour l'instant","name":"Pas de connexion Bluetooth possible"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Mortimer","datePublished":"2022-03-27T20:07:23Z","description":"L'image est superbe, quant à ses fonctionnalités, elles sont tellement nombreuses que je n'ai encore pas eu le temps de toutes les tester...","name":"Une belle bête !"}],"@context":"https://schema.org","name":"SAMSUNG 65TU7022 TV LED 4K UHD - 65 \" (163 cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB","image":"https://www.cdiscount.com/pdt2/0/2/2/4/550x550/samue65tu7022/rw/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h.jpg","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html"}</script>'''
soup = BeautifulSoup(html)

data = json.loads(soup.select_one('script[type="application/ld+json"]').text)
data['gtin']

While there is no explicit language tag mentioned this answer point out approach with python.

Select the <script> from HTML and load extracted text with json.loads():

data = json.loads(soup.select_one('script[type="application/ld+json"]').text)

Now you could pick the gtin by key:

data['gtin']

Example

html = r'''<script type="application/ld+json">{"@type":"Product","aggregateRating":{"@type":"AggregateRating","ratingValue":4.4946996466431095,"ratingCount":566,"bestRating":5.0,"worstRating":1.0},"brand":{"@type":"Organization","name":"SAMSUNG"},"description":"SAMSUNG 65TU7022 TV LED 4K - 65 \" (163cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB - Classe énergétique G","gtin":"8806090325632","offers":{"@type":"Offer","availability":"InStock","itemCondition":"NewCondition","price":615.99,"priceCurrency":"EUR","priceValidUntil":"2022-04-06T14:57:01.7797852+02:00","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html?idOffre=639618765"},"productID":"SAMUE65TU7022","category":"Téléviseur LED","sku":"samue65tu7022","review":[{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"Soso","datePublished":"2022-04-03T03:54:10","description":"Je recommande cet achat tout est parfait","name":"Parfait"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"SmashingQuasar","datePublished":"2022-04-02T14:13:11","description":"Cette télévision est grande et offre une résolution 4K pour un prix abordable. La qualité d'image est correcte sans être exceptionnelle. Le HDR est anecdotique sur ce modèle, on ne le discerne presque pas. 4 étoiles pour ce modèle simplement car la profondeur de noir est insatisfaisante. En dehors de ça, une assez bonne affaire pour ceux qui souhaitent passer à la 4K.","name":"Une grande TV 4K peu chère"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"5","worstRating":"1"},"author":"luna","datePublished":"2022-04-01T07:40:28","description":"Sa taille et les options sont au top…","name":"TRES BON CHOIX"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Sylva","datePublished":"2022-03-28T13:27:19","description":"Je viens d'acheter ce téléviseur mais malheureusement pas de connection Bluetooth possible. S'il faille le contacter avec avec une barre de son Bluetooth n'y rêvez même pas. A part ça tout est parfait pour l'instant","name":"Pas de connexion Bluetooth possible"},{"@type":"Review","reviewRating":{"@type":"Rating","bestRating":"5","ratingValue":"4","worstRating":"1"},"author":"Mortimer","datePublished":"2022-03-27T20:07:23Z","description":"L'image est superbe, quant à ses fonctionnalités, elles sont tellement nombreuses que je n'ai encore pas eu le temps de toutes les tester...","name":"Une belle bête !"}],"@context":"https://schema.org","name":"SAMSUNG 65TU7022 TV LED 4K UHD - 65 \" (163 cm) - HDR10 + - Dolby Digital Plus - Smart TV - 2xHDMI - 1xUSB","image":"https://www.cdiscount.com/pdt2/0/2/2/4/550x550/samue65tu7022/rw/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h.jpg","url":"https://www.cdiscount.com/high-tech/televiseurs/samsung-65tu7022-tv-led-4k-uhd-65-163-cm-h/f-1062613-samue65tu7022.html"}</script>'''
soup = BeautifulSoup(html)

data = json.loads(soup.select_one('script[type="application/ld+json"]').text)
data['gtin']
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文