Coding a website scraper using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ramshengale
Forum Newbie
Posts: 1
Joined: Sun Jun 24, 2012 9:28 am

Coding a website scraper using PHP

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Coding a website scraper using PHP

Post by requinix »

Why?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Coding a website scraper using PHP

Post by Jonah Bron »

What is the problem?
Post Reply