ciao ragazzi, ho un problema ho creato uno script per grabbare delle informazioni mirate da siti web...ma non riesco a inserirli nel database!!
ecco lo script
Parse.php
<?php
class ParseSite{
var $DataFromSite = '';
function __construct($url){
$this->url = $url;
$this->DataFromSite = $this->grab_page();
}
private function grab_page(){
$this->CurlOP = array(
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_USERAGENT => "LWS V1.0", // who am i
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
CURLOPT_SSL_VERIFYHOST => 0, // don't verify ssl
CURLOPT_SSL_VERIFYPEER => false, //
);
$this->ch = curl_init($this->url);
curl_setopt_array($this->ch,$this->CurlOP);
$this->Data = curl_exec($this->ch);
curl_close($this->ch);
return $this->Data;
}
function get_doctype(){
$h1tags = preg_match('/<!DOCTYPE (\w.*)dtd">/is',$this->DataFromSite,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}
// retrieve page title
function get_doc_title(){
$h1tags = preg_match('/<title> ?.* <\/title>/isx',$this->DataFromSite,$patterns);
$res = array();
array_push($res,$patterns[0]);
array_push($res,count($patterns[0]));
return $res;
}
// retrieve keywords
function get_keywords(){
$h1tags = preg_match('/(<meta name="keywords" content="(.*)" \/>)/i',$this->DataFromSite,$patterns);
$res = array();
array_push($res,$patterns[2]);
array_push($res,count($patterns[2]));
return $res;
}
}
?>
index.php
<?php
include 'parse.php';
$Parse = new ParseSite("http://www.google.com");
echo "<pre>";
var_dump(
$Parse->get_doctype(),
$Parse->get_doc_title(),
$Parse->get_keywords(),
$Parse->get_link_rel(),
$Parse->get_domain_name_only()
);
echo "</pre>";
?>