如何使用DOMXpath获取<div>标记属性

时间:2019-12-03 06:58:40

标签: php web-scraping simple-html-dom

链接= https://www.joemyerstoyota.com/new-inventory/index.htm

我的代码:

$websiteUrl = 'https://www.joemyerstoyota.com/new-inventory/index.htm';

$curl = curl_init();

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_URL, $websiteUrl);
curl_setopt($curl, CURLOPT_REFERER, $websiteUrl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$str = curl_exec($curl);

curl_close($curl);

$html_base = new simple_html_dom();
$html_base->load($str, TRUE, FALSE);

$mydata = array();

foreach($html_base->find('div.hproduct auto toyota') as $key => $element) 
{
    $mydata = $element->attr;
}

print_r($mydata);

显示空白输出。有人可以帮忙吗?

0 个答案:

没有答案