Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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
使用xpath和php获取First 100 href_Php_Html_Dom_Xpath - Fatal编程技术网

使用xpath和php获取First 100 href

使用xpath和php获取First 100 href,php,html,dom,xpath,Php,Html,Dom,Xpath,我写这段代码是为了从web资源中获取href的链接。。。该资源有1000多个链接 $dom = new DOMDocument(); @$dom->loadHTMLFile('https://www.domain.me/'); $xpath = new DOMXPath($dom); $entries = $xpath->query("//div[@class='media-body']/p/a[2]/@href"); $output = array(); 如何使用xpath-et

我写这段代码是为了从web资源中获取href的链接。。。该资源有1000多个链接

$dom = new DOMDocument();
@$dom->loadHTMLFile('https://www.domain.me/');
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//div[@class='media-body']/p/a[2]/@href");
$output = array();
如何使用xpath-etc获取来自www.domain.me的前100个链接,或来自100个的链接。到200。。。有没有办法获得100之间的链接。和200???

您可以简单地计算结果:

$links=array\u slice($links,100100)

您可以简单地查看结果:


$links=array\u slice($links,100100)

可以使用xpath的position函数

$entries = $xpath->query("//div[@class='media-body']/p/a[position()>=$start and position() <= $end]/@href");

$entries=$xpath->query(“//div[@class='media-body']]/p/a[position()>=$start and position()您可以使用xpath的position函数

$entries = $xpath->query("//div[@class='media-body']/p/a[position()>=$start and position() <= $end]/@href");

$entries=$xpath->query(“//div[@class='media-body']]/p/a[position()>=$start and position(),但我有:foreach($e){那么如何从100到200进行foreach…使用xpath魔法还有另一个答案,但如果您仍然对这种方法感兴趣,那就是:$my_entries=array_slice($entries,100100);foreach($my_entries as$e){…但是我有:foreach($e){所以如何从100到200进行foreach…使用xpath魔术还有另一个答案,但是如果您仍然对这种方法感兴趣,那就是:$my_entries=array_slice($entries,100100);foreach($my_entries as$e){。。。