2014-01-16 122 views

回答

2

你将要使用DOMDocumentDOMXPath

// if the below line does not work, you will need to use CURL or similar. 
$theHtmlToParse = file_get_contents('http://url.to/page.html'); 
$doc = new DOMDocument(); 
$doc->loadHTMLFile($theHtmlToParse); 
$xpath = new DOMXpath($doc); 
$elements = $xpath->query("*/div[@class='bio']/div[@class='value']"); 
// We now have an array of elements, or null 
if ($elements !== null) 
{ 
    foreach ($elements as $element) 
    { 
     echo "<br/>[". $element->nodeName. "]"; 

     $nodes = $element->childNodes; 
     foreach ($nodes as $node) 
     { 
      echo $node->nodeValue. "\n"; 
     } 
    } 
} 

这应该给你足够的去:)

0

是的,其实这是可能的。

你可能会使用类似visionmedia/php-selector得到的.value的 和Guzzle或一些卷曲内容之前获得源代码,如果你还没有。

0

好吧,这可以用file_get_contents()函数来完成。 只需将网页的url转入此function,然后创建一个object即可。 根据需要使用->浏览对象。