scraping problem with dom
Posted: Sat Aug 20, 2011 9:22 am
i am trying to get price witch is in div tag with class='cost', but i get much more results because of divs with classes ="cost cost_with_old". What should i do?
http://www.ishop.lt/mac-kompiuteriai/ma ... mc700.html
http://www.ishop.lt/mac-kompiuteriai/ma ... mc700.html
Code: Select all
function extract_numbers2($string)
{
preg_match_all('/([\d]+)/', $string, $match);
return $match[0];
}
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5');
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$url = 'http://www.ishop.lt/mac-kompiuteriai/macbook-pro/macbook-pro-mc700.html';
$htmlc = get_data($url);
$html = str_get_html($htmlc);
foreach($html->find('div[class="cost"]') as $e)
echo $e->outertext;
echo $e->innertext;
echo "<br><br>";
$numbers_array = extract_numbers2($e->innertext);
echo $numbers_array[0];
echo "<br><br>";