使用python和beautifulsoup从<script>中提取内容

dataLayer.push({
    "event": "ga.hit",
    "hitType": "pageview",
    "pageCategory": "Produkt",
    "userId": null,
    "userLogged": false,
    "productCategories": [
        "Laptopy i komputery",
        "Peryferia PC",
        "Monitory"
    ],
    "ecommerce": {
        "currencyCode": "PLN",
        "detail": {
            "products": [
                {
                    "name": "AOC 24G2U5/BK [1ms, 75Hz, FreeSync]",
                    "id": "666956",
                    "price": "779",
                    "brand": "AOC",
                    "category": "Monitory",
                    "variant": "",
                    "systemCode": "MON-LCD-AOC-0202",
                    "vendorCode": "24G2U5/BK",
                    "availability": "available"
                }
            ]
        }
    }
});
</script>

我想做一个价格比较工具,我想从

评论
rqui
rqui

使用正则表达式尝试一下,

import re

re.search('"price": "(.*)"', text).group(1)
点赞
评论