php - DomDocument/DOMXPath - How to get HTML Dom element by itemprop and img src -
i working on script getting data html dom elements.
here code:
<?php $url = 'http://www.sportsdirect.com/nike-satire-mens-skate-shoes-242188?colcode=24218822'; libxml_use_internal_errors(true); $doc = new domdocument(); $doc->loadhtmlfile($url); $xpath = new domxpath($doc); $name = $xpath->query('//span[@id="productname"]')->item(0)->nodevalue; echo $name; ?> this code taking text inside <span id="productname"></span>. know how data elements specific class or id.
i don't know how can src="http://adres-to-image.com/img.png" (pure example) image tag or how can elements not have id or class have attribute itemprop, example <div itemprop="name"></div>
- how can image
src? - how can elements
itemprop?
thanks in advance!
for examples:
$xpath->query('//img/@src)->item(0)->nodevalue this means
select src attributes of img tags , value of first
$xpath->query('//div/[@itemprop="name"])->item(0)->nodevalue this means
select divs itemprop attr equals name , value of first.
Comments
Post a Comment