Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 迭代不起作用,只返回一项_Xml_Xpath_Web Scraping - Fatal编程技术网

Xml 迭代不起作用,只返回一项

Xml 迭代不起作用,只返回一项,xml,xpath,web-scraping,Xml,Xpath,Web Scraping,我想刮一个论坛帖子和他们的直接网址列表。挑战在于直接链接不能构成帖子名称 下面是DOM: 我只能在结果中看到1项。下面是我写的。我的迭代逻辑正确吗 $postTitle = $xpath->query("//tr/td[@class='row1'][3]//span[1]/text()"); $postURL = $xpath->query("//tr/td[@class='row1'][3]//a/@href"); $output = '<ul>'; foreach

我想刮一个论坛帖子和他们的直接网址列表。挑战在于直接链接不能构成帖子名称

下面是DOM:

我只能在结果中看到1项。下面是我写的。我的迭代逻辑正确吗

$postTitle = $xpath->query("//tr/td[@class='row1'][3]//span[1]/text()");
$postURL = $xpath->query("//tr/td[@class='row1'][3]//a/@href");

$output = '<ul>';

foreach ($postTitle as $title) $titlesArr[] = $title->nodeValue;
foreach ($postURL as $url) $urlsArr[] = $url->nodeValue;

$nodeValues = '';

for ($i=0; $i < count($nodeValues); $i++) { 
    $output .= '<li><a target="_blank" href="' . $urlsArr[$i] . '">' . $titlesArr[$i] . '</a></li>';
}

$output .= '</ul>';

echo $output;
$postitle=$xpath->query(//tr/td[@class='row1'][3]//span[1]/text()”;
$postrl=$xpath->query(“//tr/td[@class='row1'][3]///a/@href”);
$output='
    '; foreach($postTitle作为$title)$titlesArr[]=$title->nodeValue; foreach($postrl作为$url)$urlsArr[]=$url->nodeValue; $nodeValues=''; 对于($i=0;$i
    可能是因为$nodeValues=''。那么,$i永远不会少于count($nodeValues)。
    试着去掉那条线