-1

It's simple question, but I couldn't get the h1 tag's text. DOMparser returns this error.

$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);

The text inside h1 not returning?

1
  • 1
    Because you trying to get a text from iframe, first you need to go to iframe.
    – firefly
    Commented Oct 22, 2018 at 2:14

1 Answer 1

0

You can use it like this.

$Tags = $DOMParser->getElementsByTagName('h1');
                foreach ($Tags as $h1tag) {
                        $changeForMyDB['building_name'] = trim($h1tag->nodeValue);
                }

it'll work out.