这就是我使用的:
libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("https://www.gismeteo.ru/city/weekly/4230/");
$xpath = new DomXPath($dom);
$weekday= $xpath->query('//*[@id="weather-weekly"]//div[@class="weekday"]');
$date= $xpath->query('//*[@id="weather-weekly"]//div[@class="s_date"]');
foreach ($weekday as $node4){
foreach ($date as $node3){
echo $node4->nodeValue,$node3->nodeValue,"<br>";}}
$node4->nodeValue
打印出一周中的某一天sun, mon, tue...
,$node3->nodeValue
打印出该月的某一天,如何在同一列中打印所有内容,例如sat 23.07, sun 24.08...
?感谢。
答案 0 :(得分:0)
$xpath = new DomXPath($dom);
$days = $xpath->query('//*[@id="weather-weekly"]//div[@class="wbshort"]');
foreach ($days as $day) {
// find weekday and date under day
$weekday= $xpath->query('.//div[@class="weekday"]', $day);
$date= $xpath->query('.//div[@class="s_date"]', $day);
echo $weekday->item(0)->nodeValue . " " . $date->item(0)->nodeValue;
}