php - Scraping using DomXPath -
using php domxpath scrape websites.
currently using tutorial traverse xpaths.
i scraping site, getting character names , steam id (the mess of xpath below gets 1 steam id).
my question - there multiple steam ids , character names. xpath painstakingly created gets one.
how should scrape all of steam ids instead of 1 of them?
$xpath = new domxpath($this->ourteamhtml); /* set http response header plain text debugging output */ header("content-type: text/plain"); $steamname = $xpath->query('//*[@id="wrapper"]/section/div/div[1]/div[2]/div[2]/div[1]/div/div/div[1]/div/div[1]/h5/b'); /* traverse domnodelist object output each domnode's nodevalue */ foreach ($steamname $node) { echo "steam name: " . $node->nodevalue . "\n"; }
your xpath verbose, having full path , element indexes not intuitive read , tends break due slight changes in page source. try using following simpler xpath :
//*[@id="wrapper"]//div[@class='col-md-12']//h5/b
it worked me steam id's , character names (total of 32 elements) linked page (tested using firefox's firepath add-on)
Comments
Post a Comment