I want to pull the text in the a
tags, but I don't want the text in the span class
that says "new listing". Using xpath, how can I get just the following text:
NEW! CALL OF DUTY: WWII (Microsoft XBOX ONE DISC 2017) WW2 Factory Sealed!
PHP SCRAPER
$document = new DOMDocument( '1.0', 'UTF-8' );
$document->preserveWhiteSpace = false;
$internalErrors = libxml_use_internal_errors( true );
$ebayhtml = file_get_contents( $ebayurl );
$document->loadHTML( $ebayhtml );
libxml_use_internal_errors( $internalErrors );
$xpath = new DOMXpath( $document );
$headers = $xpath->query( '//h3[@class="lvtitle"]/a' );
$ebayx = 0;
foreach ( $headers as $title ) {
if ( $ebayx > 9 ) {
break;
} else {
$header = $title->nodeValue . PHP_EOL;
$header = strlen($header) > 60 ? substr($header,0,60) . "..." : $header;
echo '<pre>';
echo $header;
echo '</pre>';
$ebayx++;
}
}
HTML CODE BEING SCRAPED
<a href="https://www.ebay.com/itm/NEW-CALL-OF-DUTY-WWII-Microsoft-XBOX-ONE-DISC-2017-WW2-Factory-Sealed/173060343645?epid=237222746&hash=item284b33475d:g:Xf4AAOSwI8laCc~I" class="vip" title="Click this link to access NEW! CALL OF DUTY: WWII (Microsoft XBOX ONE DISC 2017) WW2 Factory Sealed!"><span class="newly">New listing</span>
NEW! CALL OF DUTY: WWII (Microsoft XBOX ONE DISC 2017) WW2 Factory Sealed!</a>