我试图使用simple_html_dom.php提取信息
该行如下所示:
<meta itemprop="openingHours" content="Mo,Tu,We,Th,Fr,Sa,Su 08:00-00:00">
我需要“ Mo,Tu,We,Th,Fr,Sa,Su 08:00-00:00”部分。
这是我到目前为止尝试过的:
$url="https://www1.shoppersdrugmart.ca/en/store-locator/store/668";
include ('../classes/simple_html_dom.php');
$html = file_get_html($url);
//this works fine
$eg = $html->find('dd[itemprop="telephone"]');
echo "Phone: ".$eg[0]->plaintext. "<br>";
//this does not work
$eg = $html->find('meta[itemprop="openingHours"]');
echo "openingHours: ". $eg['content']->plaintext. "<br>";
$oh_content=$html->find('meta[itemprop="openingHours"]')->attr("content");
echo $oh_content."*<br>";
$oh_content1=$html->find('meta[itemprop="openingHours"]')->content;
echo $oh_content1."*<br>";
答案 0 :(得分:0)
在$eg = $html->find('dd[itemprop="telephone"]');
中,$eg
是已过滤节点的数组,然后对于第二个find
,它是 true :>
$eg = $html->find('meta[itemprop="openingHours"]');
// $eg is array:
var_dump($eg[0]->content);
答案 1 :(得分:0)
万一有人需要,下面的代码可以工作:
$url="https://www1.shoppersdrugmart.ca/en/store-locator/store/668";
include ('../classes/simple_html_dom.php');
$html = file_get_html($url);
$eg = $html->find('dd[itemprop="telephone"]');
echo "Phone: ".$eg[0]->plaintext. "<br>";
$eg = $html->find('meta[itemprop="openingHours"]');
echo "openingHours: ". $eg[0]->content. "<br>";