@ 2019-05-15T01:58:35Z <?php
class scraper
{
public static $response;
public static $dom;
// randomize useragent string
public static function get_useragent()
{
$ua = array(
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_1) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25",
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
);
shuffle($ua);
$x = array_rand($ua);
return $ua[$x];
}
// download using curl
public static function data_download($_url)
{
if(!function_exists('curl_init'))
{
die('Sorry cURL is not installed!');
}
try
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_url);
curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/");
curl_setopt($ch, CURLOPT_USERAGENT, self::get_useragent());
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
catch(Zend_Exception $e)
{
echo 'Caught Exception: ' . get_class($e) . "\n";
echo 'Message: ' . $e->getMessage() . "\n";
}
}
public static function data_cache($url)
{
$cache = Zend_Registry::get('cache');
$cache_id = md5($url);
try
{
if(!$response = $cache->load($cache_id))
{
// delay execution for a few seconds at random
//sleep(rand(5, 15));
$response = trim(self::data_download($url));
$response = $cache->save($response, $cache_id);
$response = $cache->load($cache_id);
self::$response = $response;
}
else
{
$response = $cache->load($cache_id);
self::$response = $response;
}
}
catch(Zend_Exception $e)
{
echo 'Caught Exception: ' . get_class($e) . "\n";
echo 'Message: ' . $e->getMessage() . "\n";
}
}
public static function query_css($query)
{
$html = self::$response;
$dom = new Zend_Dom_Query($html);
$results = $dom->query($query);
return $results;
}
public static function query_xpath($query)
{
$html = self::$response;
$dom = new Zend_Dom_Query($html);
$results = $dom->queryXpath($query);
;
return $results;
}
public static function load_pq_dom()
{
try
{
$html = self::$response;
$dom = phpQuery::newDocumentHTML($html);
self::$dom = $dom;
}
catch(Zend_Exception $e)
{
echo 'Caught Exception: ' . get_class($e) . "\n";
echo 'Message: ' . $e->getMessage() . "\n";
}
}
public static function query_pq($query)
{
self::load_pq_dom();
$dom = self::$dom;
$dom = $dom->find($query);
$result = $dom->html();
return $result;
}
public static function parse_table($query, $_key, $_value)
{
self::load_pq_dom();
$dom = self::$dom;
foreach(pq($query) as $block)
{
$key = trim(pq($_key, $block)->text());
$value = trim(pq($_value, $block)->text());
$array[$key] = $value;
}
return $array;
}
public static function parse_list($query)
{
self::load_pq_dom();
$dom = self::$dom;
foreach(pq($query) as $block)
{
$list_item = trim(pq('ul li', $block)->text());
$array[] = $list_item;
}
return $array;
}
public static function parse_options($query)
{
self::load_pq_dom();
$dom = self::$dom;
foreach(pq($query) as $block)
{
$list_item = trim(pq('option', $block)->text());
$array[] = $list_item;
}
return $array;
}
public static function parse_links($query)
{
$dom = self::$dom;
$a = self::query_css($query);
foreach($a as $href)
{
$links[] = $href->getAttribute('href');
}
return $links;
}
public static function setup_database($host, $db_name, $user, $password)
{
Zend_Loader_Autoloader::getInstance()->registerNamespace("RedBean_");
R::setup("mysql:host={$host}; dbname={$db_name}", $user, $password);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.1 0.013 0.003 14.81 7.4.0 0.012 0.004 14.97 7.3.13 0.006 0.012 15.01 7.3.12 0.014 0.003 14.73 7.3.11 0.012 0.006 14.46 7.3.10 0.004 0.011 14.37 7.3.9 0.004 0.008 14.92 7.3.8 0.003 0.012 14.87 7.3.7 0.003 0.010 14.59 7.3.6 0.004 0.011 14.73 7.3.5 0.009 0.006 14.52 7.3.4 0.003 0.007 14.54 7.3.3 0.005 0.011 14.64 7.3.2 0.009 0.007 15.58 7.3.1 0.009 0.007 15.52 7.3.0 0.014 0.007 15.64 7.2.26 0.004 0.014 14.71 7.2.25 0.003 0.013 14.67 7.2.24 0.004 0.012 14.86 7.2.23 0.004 0.011 15.14 7.2.22 0.013 0.000 14.71 7.2.21 0.006 0.009 14.69 7.2.20 0.004 0.011 14.80 7.2.19 0.000 0.012 14.91 7.2.18 0.003 0.013 14.94 7.2.17 0.010 0.009 14.77 7.2.16 0.006 0.010 14.84 7.2.15 0.011 0.005 15.73 7.2.14 0.003 0.012 15.80 7.2.13 0.006 0.008 15.66 7.2.12 0.007 0.011 15.72 7.2.11 0.012 0.008 15.82 7.2.10 0.051 0.005 15.71 7.2.9 0.009 0.012 15.80 7.2.8 0.011 0.005 15.73 7.2.7 0.006 0.011 15.73 7.2.6 0.008 0.011 15.72 7.2.5 0.011 0.009 15.82 7.2.4 0.009 0.006 15.82 7.2.3 0.005 0.009 15.94 7.2.2 0.013 0.006 15.83 7.2.1 0.004 0.013 15.81 7.2.0 0.012 0.008 15.83 7.1.33 0.003 0.013 15.46 7.1.32 0.010 0.003 15.76 7.1.31 0.000 0.014 15.67 7.1.30 0.005 0.008 15.45 7.1.29 0.006 0.006 15.61 7.1.28 0.006 0.014 14.70 7.1.27 0.012 0.002 14.76 7.1.26 0.012 0.007 14.63 7.1.25 0.005 0.007 14.77 7.1.24 0.010 0.003 15.32 7.1.23 0.011 0.003 15.33 7.1.22 0.010 0.003 15.71 7.1.21 0.008 0.004 15.52 7.1.20 0.006 0.010 15.66 7.1.19 0.006 0.006 15.68 7.1.18 0.010 0.003 15.41 7.1.17 0.007 0.004 15.62 7.1.16 0.012 0.003 15.50 7.1.15 0.006 0.009 15.77 7.1.14 0.009 0.006 15.34 7.1.13 0.010 0.000 15.75 7.1.12 0.004 0.004 15.55 7.1.11 0.003 0.009 15.54 7.1.10 0.014 0.000 15.75 7.1.9 0.006 0.006 15.59 7.1.8 0.006 0.006 15.33 7.1.7 0.004 0.011 15.50 7.1.6 0.006 0.009 15.56 7.1.5 0.010 0.006 15.76 7.1.4 0.003 0.012 15.55 7.1.3 0.006 0.006 15.63 7.1.2 0.007 0.007 15.62 7.1.1 0.013 0.003 15.56 7.1.0 0.003 0.007 15.70
preferences:dark mode live preview
34.26 ms | 401 KiB | 5 Q