PHP/DOMXpath/DOMDocument-无法分析特定链接
这是我的代码,您可以复制并粘贴它以开始运行,测试完成:PHP/DOMXpath/DOMDocument-无法分析特定链接,php,domdocument,domxpath,Php,Domdocument,Domxpath,这是我的代码,您可以复制并粘贴它以开始运行,测试完成: <?php $url = "http://www.sportsdirect.com/ladies/ladies-underwear"; libxml_use_internal_errors(true); $doc = new DOMDocument(); $doc->loadHTMLFile($url); $xpath = new DOMXpath($doc); $n = $xpath->query('//div
<?php
$url = "http://www.sportsdirect.com/ladies/ladies-underwear";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
$xpath = new DOMXpath($doc);
$n = $xpath->query('//div[@class="s-producttext-top-wrapper"]');
$l = $xpath->query('//div[@class="s-producttext-top-wrapper"]/a');
$p = $xpath->query('//div[@class="s-largered"]');
$nl = $xpath->query('//a[@class="swipeNextClick NextLink"]');
$NextLink = $nl->item(0)->getAttribute("data-dcp");
$item = 0;
foreach ($n as $entry) {
$Name = $entry->nodeValue;
$Link = $l->item($item)->getAttribute("href");
$Price = $p->item($item)->nodeValue;
$Find = array('£');
$Replace = array('');
$Price = str_replace($Find, $Replace, $Price);
echo "Name: $Name - Link: $Link - Price: $Price - $NextLink<br>";
$item++;
}
?>
我仍然得到第一页产品的结果。为什么?
如何解析第2页中的所有产品,我的错误在哪里
你能帮帮我吗
提前谢谢
<?php
$url = "http://www.sportsdirect.com/ladies/ladies-underwear#dcp=2&dppp=100&OrderBy=rank";
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
$xpath = new DOMXpath($doc);
$n = $xpath->query('//div[@class="s-producttext-top-wrapper"]');
$l = $xpath->query('//div[@class="s-producttext-top-wrapper"]/a');
$p = $xpath->query('//div[@class="s-largered"]');
$nl = $xpath->query('//a[@class="swipeNextClick NextLink"]');
$NextLink = $nl->item(0)->getAttribute("data-dcp");
$item = 0;
foreach ($n as $entry) {
$Name = $entry->nodeValue;
$Link = $l->item($item)->getAttribute("href");
$Price = $p->item($item)->nodeValue;
$Find = array('£');
$Replace = array('');
$Price = str_replace($Find, $Replace, $Price);
echo "Name: $Name - Link: $Link - Price: $Price - $NextLink<br>";
$item++;
}
?>