之前,当我使用.li中的填充解析页面时,一切都很好,但是当我使用更改功能的相同方法解析新页面时,没有错误,并且解析拒绝
更早...
页面中:
<div class="block-content content">
<article>
...
</article>
<div class="pagination"><div class="item-list"><ul class="pager pager-regular"><li class="pager-item pager-previous first"> </li>
<li class="pager-item pager-current">1</li>
<li class="pager-item"><a title="2" href="/frontpage?page=1">2</a></li>
代码:
function parser_simple_html($url, $i){
if($i < 3) {
$html = str_get_html(get_result($url));
$blog = $html->find(".block-content", 0);
foreach($blog->find("article") as $root)
{
print "<pre>" . $root->find('p', 0)->plaintext . "</pre>";
}
if (isset($blog->find('li.pager-current', 0)->next_sibling()->find('a', 0)->href) && !empty($blog->find('li.pager-current', 0)->next_sibling()->find('a', 0)->href)) {
$href = $blog->find('li.pager-current', 0)->next_sibling()->find('a', 0)->href;
$i++;
parser_simple_html("https://site.st" . $href, $i);
}
}
}
parser_simple_html('https://site.st/', $i);
现在
页面:
<div class="obj">
<p>
...
</p>
div class="total totalB">`
<p class="paging">`
<b>1</b>`
<a href="/?page=2">2</a>
<a href="/?page=3">3</a>
代码:
function parser_simple_html($url, $i){
if($i < 3) {
$html = str_get_html(get_result($url));
$blog = $html->find(".obj");
$pad = $html->find('.totalB');
foreach($blog as $root)
{
print "<pre>" . $root->plaintext . "</pre>";
print '<hr>';
}
foreach($pad as $p)
{
if (isset($p->find('p.paging', 0)->next_sibling()->find('a', 0)->href) && !empty($p->find('p.paging', 0)->next_sibling()->find('a', 0)->href)) {
$href = $p->find('p.paging', 0)->next_sibling()->find('a', 0)->href;
$i++;
parser_simple_html("https://site2.st" . $href, $i);
}
}
}
}
parser_simple_html('https://site2.st/', $i);
如何使用此填充浏览页面进行解析?