Curl特定的div类文本并重新显示?php

Curl特定的div类文本并重新显示?php,php,curl,Php,Curl,我对PHP非常陌生,我知道如何对任何具有ID的H2执行此操作,例如,因为我偶然发现了一个很好的示例: <?php $html = file_get_contents('http://pokemondb.net/evolution'); //get the html returned from the following url $pokemon_doc = new DOMDocument(); libxml_use_internal_errors(TRUE); //disable l

我对PHP非常陌生,我知道如何对任何具有ID的H2执行此操作,例如,因为我偶然发现了一个很好的示例:

<?php
$html = file_get_contents('http://pokemondb.net/evolution'); //get the html 
returned from the following url

$pokemon_doc = new DOMDocument();

libxml_use_internal_errors(TRUE); //disable libxml errors

if(!empty($html)){ //if any html is actually returned

$pokemon_doc->loadHTML($html);
libxml_clear_errors(); //remove errors for yucky html

$pokemon_xpath = new DOMXPath($pokemon_doc);

//get all the h2's with an id
$pokemon_row = $pokemon_xpath->query('//h2[@class]');

if($pokemon_row->length > 0){
    foreach($pokemon_row as $row){
        echo $row->nodeValue . "<br/>";
    }
}
}
?>
然而,这不起作用,它没有那么灵活。我需要一种新的方法来引用div类。你有没有想过我需要什么?真的很感激!
-威尔逊问题解决了。这并不完美,但这确实有效

<?php 

$doc = new DOMDocument;

// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;

// Most HTML Developers are chimps and produce invalid markup...
$doc->strictErrorChecking = false;
$doc->recover = true;

$doc->loadHTMLFile('http://www.nbcnews.com/business');

$xpath = new DOMXPath($doc);

$query = "//div[@class='market']";

$entries = $xpath->query($query);
var_dump($entries->item(0)->textContent);

?>

或者,如果有人知道一个使用不同方法对特定div进行卷曲的工作示例,那么这完全是可行的。看看下面的示例是否是您想要的。谢谢你的评论。我看到了其中的逻辑,但不能完全插入到上面的工作代码中。有什么建议可以让这一切一起运行吗?这是提供的代码:foreach($xpath->query('//div[@class=“parbase cn_text”]”)作为$div){$num++;echo“$num.”;//?echo$div->textContent;echo“
”;}
//get all the h2's with an id
$pokemon_row = $pokemon_xpath->query('//marketdata[@class]');
<?php 

$doc = new DOMDocument;

// We don't want to bother with white spaces
$doc->preserveWhiteSpace = false;

// Most HTML Developers are chimps and produce invalid markup...
$doc->strictErrorChecking = false;
$doc->recover = true;

$doc->loadHTMLFile('http://www.nbcnews.com/business');

$xpath = new DOMXPath($doc);

$query = "//div[@class='market']";

$entries = $xpath->query($query);
var_dump($entries->item(0)->textContent);

?>