In teoria salvo ogni contenuto in un array e poi, nel momento della stampa, faccio passare tutti i valori dell'array...
comunque vi posto il codice della classe principale, quello che parsa i contenuti...
Codice PHP:
<?php
set_time_limit(180);
include_once("simple_html_dom.php");
include_once("class.elem.php");
class EbayAnnounceParser {
//Environment's variables
public $html;
public $page;
public $url;
public $string_search;
public $price_min;
public $price_max;
public $element;
function __construct() {
$this->html = new simple_html_dom();
$this->element = new Elem();
$this->url = "http://annunci.ebay.it";
$this->price_min = "60";
$this->price_max = "110";
}
//Load research on memory and inside "element" array
public function Load($string_search) {
$strsrc = $this->url."/".urlencode($string_search)."/";
$this->string_search = $string_search;
$page = $this->html->load_file($strsrc);
$number_of_pages = round(($this->getNumberOfResults_int())/30);
$this->LoadImageOnElement();
$this->LoadTitleOnElement();
$this->LoadDescriptionOnElement();
$this->LoadPriceOnElement();
$this->LoadLocationOnElement();
$this->LoadDateOnElement();
for($i = 1;$i<$number_of_pages;$i++) {
$strsrc = $this->url."/".urlencode($string_search)."/?p=".$i;
$this->html->load_file($strsrc);
$this->LoadImageOnElement();
$this->LoadTitleOnElement();
$this->LoadDescriptionOnElement();
$this->LoadPriceOnElement();
$this->LoadLocationOnElement();
$this->LoadDateOnElement();
sleep(1);
}
}
public function LoadImageOnElement() {
$images = $this->html->find("img");
$cont = 0;
foreach($images as $key => $value) {
//$cont = $this->html->src;
if($cont>=2 && $cont<=32)
$this->element->IMAGE[] = $value;
$cont++;
}
return;
}
public function LoadTitleOnElement() {
$titles = $this->html->find("h2.postTitle");
foreach($titles as $key => $value) {
$this->element->TITLE[] = $value;
}
return;
}
public function LoadDescriptionOnElement() {
$descriptions = $this->html->find("div.searchResultDescriptionList");
foreach($descriptions as $key => $value) {
$this->element->DESCRIPTION[] = $value;
}
return;
}
public function LoadPriceOnElement() {
$prices = $this->html->find("div.[class=searchResultPriceList column grid_1]");
$price = Array();
foreach($prices as $key => $value) {
//preg_match('/[0-9]+/', $value, $price);
$this->element->PRICE[] = $value;
unset($price);
}
return;
}
public function LoadLocationOnElement() {
$locations = $this->html->find("div.[class=searchResultLocationList column grid_2img]");
foreach($locations as $key => $value) {
$this->element->LOCATION[] = $value;
}
return;
}
public function LoadDateOnElement() {
$date = $this->html->find("div.[class=searchResultDateList column grid_1]");
foreach($date as $key => $value) {
$this->element->DATE[] = $value;
}
return;
}
public function ParseAnnounce () {
$div = $this->html->find("div.[class=searchResultListItem row]");
foreach($div as $key => $value) {
}
return;
}
//Get the number of results of a search string given by user
public function getNumberOfResults() {
$element_numbers = $this->html->find("span.count");
return trim($element_numbers[0]->innertext);
}
public function getNumberOfResults_int() {
$element_numbers = $this->html->find("span.count");
$num = trim($element_numbers[0]->innertext);
return str_replace(".", "", $num);
}
}
?>