我想提取网站的所有属性name=""
,
示例html
<div class="link_row">
<a href="" class="listing_container" name="7777">link</a>
</div>
我有以下代码:
<?php
$html = new DOMDocument();
@$html->loadHtmlFile('http://www.onedomain.com/plus?ca=11_c&o=1');
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( "//div[@class='link_row']/a[@class='listing_container']/@name" );
foreach ($nodelist as $n){
echo $n->nodeValue."\n<br>";
}
?>
结果是:
7777
http://www.onedomain.com/plus?ca=11_c&o=1
寻呼机attr为"o=1"
我想在您完成o=1
后,请关注o=2
我定义的变量$last=556
等于http://www.onedomain.com/plus?ca=11_c&o=556
由于
答案 0 :(得分:1)
使用for(或while)循环。我在您提供的代码中看不到$last
,因此我已静态设置最大值加一。
$html = new DOMDocument();
for($i =1; $i < 557; $i++) {
@$html->loadHtmlFile('http://www.onedomain.com/plus?ca=11_c&o=' . $i);
$xpath = new DOMXPath( $html );
$nodelist = $xpath->query( "//div[@class='link_row']/a[@class='listing_container']/@name" );
foreach ($nodelist as $n){
echo $n->nodeValue."\n<br>";
}
}
更简单的例子:
for($i =1; $i < 557; $i++) {
echo $i;
}