这是一个简单的问题,但是我无法获得$results = 'http://www.daikyo.co.jp/KOBETSU/MF081014/gaiyo_chg.html?_ga=2.231780890.465420601.1540169716-1978642370.1538226055&_bdld=HYzpv.moBqKE6';
$html = file_get_contents($results);
$DOMParser = new \DOMDocument();
$DOMParser->loadHTML($html);
$changeForMyDB = [
'region' => '関西',
'link' => json_encode($results),
'building_name' => '',
'price' => '',
'old_price' => '',
'extend' => '',
'address' => '',
'total_house' => '',
'rooms' => '',
'cons_finish' => '',
'entry' => '',
'balcony' => '',
'company_name' => '',
'list_from' => 'daikyo'
];
$changeForMyDB['building_name'] = trim($DOMParser->getElementsByTagName('h1')->nodeValue);
标签的文本。 DOMparser返回此错误。
def unique(s):
return len(s) == len(set(s))
h1中的文本不返回?
答案 0 :(得分:0)
您可以像这样使用它。
$Tags = $DOMParser->getElementsByTagName('h1');
foreach ($Tags as $h1tag) {
$changeForMyDB['building_name'] = trim($h1tag->nodeValue);
}
会解决的。