[ create a new paste ] login | about

Link: http://codepad.org/tiI5vfRD    [ raw code | fork ]

ninwa - PHP, pasted on Jun 30:
<html>
<head>
	<title> Froogle Scraper </title>
</head>

<body>
<?php
	
	$s = $_GET['s'];
	include ('index.html');

	if( $s != "" ){
		echo ("<hr>");
		
		/* PHP Simple HTML DOM Parser - http://simplehtmldom.sourceforge.net/ */
		include_once('./simplehtmldom/simple_html_dom.php');
		$link  = "http://www.google.com/products?q={$s}";
		$html = file_get_html($link);
		
		echo ("<center> HTML being scraped from: <a href=\"{$link}\">{$link}</a>");
		
		$names[] = "";
		$links[] = "";
		foreach( $html->find('p[class=result-image]') as $product ){
			$name = $product->find("img",0)->getAttribute('alt');
			$link = $product->find('a' ,0)->getAttribute('href');
			
			array_push($names,$name);
			array_push($links,$link);
		}
		

		$prices[] = "";
		foreach( $html->find('span[id^=price]') as $product ){
			$price = $product->find("span.main-price",0)->plaintext;
			
			array_push($prices,$price);
		}
		
		if ( count($names) == 1 ){
			echo("<br><br> <b> No results </b>");
		}
		else{
			
			echo("<br><br><table width=80%>");
			echo("<tr bgcolor=#777777><td align=\"center\"> Title </td><td> Price </td></tr>");
			
			for( $i = 1; $i < count($names); $i++ ){
				$link = "http://www.froogle.com" . $links[$i];
				if($i % 2 == 0 ) echo("<tr bgcolor=#aaaaaa><td align=\"center\"> <a href={$link}>{$names[$i]}</a> </td><td>{$prices[$i]}</td> </tr> ");
				else  echo("<tr bgcolor=#cccccc><td align=\"center\"> <a href={$link}>{$names[$i]}</a> </td><td>{$prices[$i]}</td> </tr> "); 
			}
			echo("</table>");
		}
	}
?>


Create a new paste based on this one


Comments: