我想抓取页面的内容,实际上只是该页面中的一个 div,并将其显示给网页上的一个小 div 内的用户。我只需要来自需要用户凭据的 carfax 页面的一条信息,因此我无法发布确切的代码,但我尝试使用 google.com 并遇到同样的问题,因此解决方案应该交叉。
现在我已经尝试过了:
$webPage = file_get_contents('http://www.google.com');
$doc = new DOMDocument();
$doc->loadHTML($webPage);
$div = $doc->getElementById('lga');//this is the id to the div holding the image above the textbox
//echo $webPage;//this displays www.google.com minus the image. I imagine because of the file path
//var_dump($div);//this display "object(DOMElement)#2 (0) { }" and I'm not sure what that means
//echo $div;//this has a server error
我也在查看 simple_html_dom.php 试图弄清楚这一点。