也许这会有所帮助(顺便说一下,它不需要 SimpleHTMLDom):
$className = 'prc'; // Name of the class
$domDocument = new DOMDocument('1.0');
@$domDocument->loadHTMLFile('http://www.ebay.in');
$domXPath = new DOMXPath($domDocument);
// Obtain all elements with the specified class name
$prcs = $domXPath->query(
"//*[contains(concat(' ', normalize-space(@class), ' '), ' $className ')]"
);
for ($i = 0; $i < $prcs->length; $i++) {
// For each item found, store it in $result
$result[] = $prcs->item($i)->firstChild->nodeValue;
}
// Display results
print_r($result);