| Server IP : 103.48.194.25 / Your IP : 216.73.216.33 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hocthongminh.net-bk/public_html/webadmin/components/robot/libraries/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
include_once("simple_html_dom.php");
class Crawl
{
var $html_content = '';
var $arr_att_clean = array();
function Crawl(){
// nothing to do
}
function robot(){
return $html = new simple_html_dom();
}
function getHTML($link)
{
if($this->html_content==''){
$html = file_get_html($link);
$this->html_content = $html;
}else{
$html = $this->html_content;
}
//trit($html);
return $html ; //type object
}
function getNodes($html, $rule, $num=-1)
{
$arr = array();
if($num==-1)
foreach($html->find($rule) as $e)
array_push($arr, $e->innertext);
else
foreach($html->find($rule,$num) as $e)
array_push($arr, $e->innertext);
return $arr;
}
function getLink($html, $rule, $num=-1)
{
$arr = array();
if($num==-1)
foreach($html->find($rule) as $e)
array_push($arr, $e->href);
else
foreach($html->find($rule,$num) as $e)
array_push($arr, $e->href);
return $arr;
}
function getContent($link, $att_content)
{
if($this->html_content==''){
$html = file_get_html($link);
$this->html_content = $html;
}else{
$html = $this->html_content;
}
foreach($html->find($att_content) as $e){
$content_html = $e->innertext;
}
$html = str_get_html($content_html);
foreach($this->arr_att_clean as $att_clean){
foreach($html->find($att_clean) as $e){
$e->outertext = '';
}
}
$ret = $html->save();
return $ret;
}
function removeLink($content)
{
$html = str_get_html($content);
// link content
foreach($html->find('a') as $e){
$e->outertext = $e->innertext;
}
$ret = $html->save();
return $ret;
}
function removeLastElement($content, $element)
{
$html = str_get_html($content);
// link content
$html->find($element, -1)->outertext = '';
$ret = $html->save();
return $ret;
}
function removeFirstElement($content, $element)
{
$html = str_get_html($content);
$html->find($element, 0)->outertext = '';
$ret = $html->save();
return $ret;
}
}