Page 1 of 1

Coding a website scraper using PHP

Posted: Sun Jun 24, 2012 9:32 am
by ramshengale
Hello all, I want to scrape contents from a shopping site. I want to scrape image of product, name and its price from the first result in search page. I tried this code but there's some problem in it.

index.html (to search a product)

<html>
<body>

<form name="search" action="search.php" method="get">
Search Product: <input type="text" name="sword">
<input type="submit" value="Compare Prices">
</form>
<?php include ("result.php"); ?>
</body>
</html>

search.php

<?php
$sword=$_GET['sword'];
$infibeam = file_get_contents("http://www.infibeam.com/search?q=$sword");
preg_match('#<img src="http://cdn-img-a.infibeam.net/img/(.+?)>#', $infibeam, $match);
$imgurl = $match[1];
preg_match('#<span class="showcaseTitle">(.*)</span>#', $infibeam, $matchs);
$name = $matchs[1];
preg_match('#<span class="normal">(.*)</span>#', $infibeam, $match);
$price = $match[1];
echo "<img src='http://cdn-img-a.infibeam.net/img/(.*) >";
echo "Name: $name";
echo "Price: $price";
?>


Hope someone can help me with this.

Re: Coding a website scraper using PHP

Posted: Sun Jun 24, 2012 3:31 pm
by requinix
Why?

Re: Coding a website scraper using PHP

Posted: Sun Jun 24, 2012 4:41 pm
by Jonah Bron
What is the problem?