【问题标题】:Scrapy to crawl LD JSON dataScrapy 爬取 LD JSON 数据
【发布时间】:2023-04-07 14:17:02
【问题描述】:

我已经进行了一些研究,但似乎无法找到任何有关是否可以从 URL 中抓取 JSON Schema 数据之类的信息。我在看产品时发现的一个例子是:

https://www.reevoo.com/p/panasonic-nn-e271wmbpq

    <script class="microdata-snippet" type="application/ld+json">
{
  "@context": "http://schema.org/",
  "@type": "Product",
  "name": "PANASONIC NN-E271WMBPQ",
  "image": "https://images.reevoo.com/products/3530/3530797/550x550.jpg?fingerprint=73ed91807dac7eb8f899757a348c735446d0a1fe&gravity=Center"


    ,"category": {
      "@type": "Thing",
      "name": "Microwave",
      "url": "https://www.reevoo.com/browse/product_type/microwaves"
    }



    ,"description": "Auto weight programs will automatically calculate the cooking time, once the weight has been entered. Acrylic lining makes cleaning easy, simply wipe after use. Child lock provides extra security to prevent little fingers interfering with the programming of the oven. \nAll our compact microwave ovens are packed with flexible features to make everyday cooking simple. Auto weight programs will automatically calculate the cooking time, once the weight has been entered. Acrylic lining makes cleaning easy, simply wipe after use. Child lock provides extra security to prevent little fingers interfering with the programming of the oven."



    ,"aggregateRating": {
      "@type": "AggregateRating",
      "ratingValue": "8.7",
      "ratingCount": 636,
      "worstRating": "1",
      "bestRating": "10"
    }

}
</script>

那么是否有可能提取评级数据?

提前致谢,

【问题讨论】:

    标签: python scrapy


    【解决方案1】:
    import json
    

    接下来在你的代码中:

    microdata_content = response.xpath('//script[@type="application/ld+json"]/text()').extract_first()
    microdata = json.loads(microdata_content)
    
    ratingValue = microdata["aggregateRating"]["ratingValue"]
    

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 2022-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      • 1970-01-01
      • 2021-02-10
      • 2017-09-28
      相关资源
      最近更新 更多