如何从此DOMobject获取“价格和图像密钥”值

问题描述 投票:1回答:1

如何从下面获得价格和图像值。

DOMElement对象([tagName] => script [schemaTypeInfo] => [nodeName] => script [nodeValue] => {“@ context”:“https://schema.org”,“@ type”:“ItemList”,“itemListElement”:[{ “offer”:{“priceCurrency”:“Rs。”,“@ type”:“Offer”,“price”:“133998.00”,“availability”:“https://schema.org/InStock”},“image”:“https://static-01.daraz.pk/p/267cc89e2ff3e886b6bded905007d0a9.jpg”,“@输入“:”产品“,”名称“:”Galaxy Note 9 - 6.4 \“ - 6Gb Ram - 128Gb Rom - Dual Sim - Ocean Blue”,“url”:“https://www.daraz.pk/products/samsung-galaxy-note-9-64-6gb-ram-128gb-rom-dual-sim-ocean-blue-i100262063-s1222963201.html?search=1”},{“offers”:{“priceCurrency “:”Rs。“,”@ type“:”Offer“,”price“:”111999.00“,”availability“:”https://schema.org/InStock“},”image“:”https://static-01.daraz.pk/original/1da238a72d721dd92c6db87176479b47.jpg“,”@ type“:”Product“, “名称”:“Galaxy S9 + - 6.2”QHD + - 6GB内存--128GB ROM - 12/12 / 8MP相机 - 钛灰“,”网址“:”https://www.daraz.pk/products/galaxy-s9-62-qhd-6gb-ram-128gb-rom-12128mp-camera-titanium-gray-i1487172-s9267151.html?search=1“}

php json xpath web-scraping simplexml
1个回答
0
投票

您需要不断解决问题,并一次解决一项任务:

  1. 在页面上找到您想要的内容。 (完成)。
  2. 忽略页面上的其他内容,找到访问该部分的方法。 (完成)。
  3. 忽略该元素的其余部分,只获取其字符串内容。此时您无需其他HTML,因此DOM不会帮助您超越这一点。
  4. 忽略关于你如何得到它的一切,并查看该字符串的结构,并找出如何解析它。提示:它看起来像JSON,PHP内置了处理JSON的函数。
  5. 解析完字符串后,从中获取所需的信息。此时,你甚至不需要知道字符串是什么样的,你只需要一个PHP数组或对象。
© www.soinside.com 2019 - 2024. All rights reserved.