Extracting data from HTML using PHP and xPath

前端 未结 2 1616
轻奢々
轻奢々 2020-12-21 15:45

I am trying to extract data from a webpage to insert it to a database. The data I\'m interested in is in the div\'s which have a class=\"company\". On one webpage there are

2条回答
  •  自闭症患者
    2020-12-21 16:31

    To check if a node exists, verify that the length property is equal to 1 in the returned query result:

    if ($company_name->length == 1) {
       $object->company_name = trim($company_name->item(0)->nodeValue);
    }
    

提交回复
热议问题