添加数量的html标签,获取页面html标签数量的好方法

我正在寻找一种很好的方法来做到这一点:我目前的方法似乎不允许超过30-40的搜索深度,即使编辑了php.ini设置后希望增加默认执行时间以及最大内存使用量。基本上,只要搜索深度超过这个数量,服务器就会崩溃。获取页面html标签数量的好方法

这里是我的代码(private function _ParseHtml($html, $depth = nDepth):

if ($depth === 0)

{

return;

}

@$this->_dom->loadHTML($html);

$this->nodes = $this->_dom->childNodes;

$html = array();

$iterCount = 0;

foreach($this->nodes as $node)

{

if($node->hasChildNodes())

{

$html[$iterCount++] = $node->C14N();

}

$this->_tagCount++;

if ($this->_config['Debug']) _wrapBreak("Tag Count incremented");

}

if(count($html) > 0)

{

$static_depth = $depth - 1;

foreach($html as $parse)

{

$this->_ParseHtml($parse, $static_depth);

if ($this->_config['Debug']) _wrapBreak("ParseHtml did return");

}

}

_wrapBreak("Current Depth => {$depth}");

以及针对刮_Invoke()功能的主要代码:

$handle = curl_init($this->_url);

curl_setopt($handle, CURLOPT_BUFFERSIZE, self::BUFSIZE); //BUFSIZE == 50000

curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);

curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);

$this->_data['html'] = curl_exec($handle);

curl_close($handle);

$this->_ParseHtml($this->_data['html']);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值