Saturday July 31, 2010

Basic eBay Search Parsing

Conclusion
To use this script, simply call the PHP file and append "?searchstring=<text_you_want_to_search>" onto the URL. So, for instance -- "www.yourdomain.com/ebayscrape.php?searchstring=batman" would bring back results for "Batman". Again, this is a semi-basic way to parse eBay's pages to serve only as an example of a way to accomplish similar tasks. It will likely not work in the near future, as eBay is constantly changing it's pages.. however the basic premises of parsing should be applicable to other uses. Currently this script would only grab the first page of auction results (ie.. the auctions ending soonest) and you are limited to searching for single words. Further coding would have to be done to grab additional pages of results or entering multiple search terms. In addition, the results would also need to be cleaned up further to use this for anything practical, as they will contain dirty HTML code (extra tags).

The full source code to this script is below:
<?
/*******************************************************************
 Filename: ebayparser.php
 Description:
 This script is to demonstrate a technique to parse eBay auctions.

 Author: Wayne Eggert
 Last Updated: December 2004
*******************************************************************/

$URL "http://search.ebay.com/search/search.dll?query=".$searchstring."&sosortproperty=1&ht=1&from=R10&BasicSearch=";
$file fopen("$URL""r");
$r "";
do{
    
$data fread($file8192);
    
$r .= $data;
}
while(
strlen($data) != 0);

$ebayTABLEArray preg_split ("/<table.*?>/"$r);

// now try to find which <table> contains the search results are
for($x=0$x<count($ebayTABLEArray); $x++){
    if(
strstr($ebayTABLEArray[$x],"Customize Display")){ // this is text
        
$resultTable $x+1;
    }
}

$ebayTRArray preg_split("/<tr.*?>/",$ebayTABLEArray[$resultTable]);

echo 
"<BR><B>Ebay Results:</B><BR><BR>";
$start=2;
$end $start count($ebayTRArray);

for(
$i=$start;$i<$end;$i++){
    
$ebayTDArray preg_split ("/<td.*?>/",$ebayTRArray[$i]);
    
//print_r($ebayTDArray);
    
preg_match("/<a.*?<\/a>/",$ebayTDArray[4],$match);
    
$item strip_tags($match[0],"<A></A>");
    
    if(
$item!=""){
        
$item_name $item;
        
$price strip_tags($ebayTDArray[6]);
        
// see if there's a Buy-It-Now price
        
$priceArray explode("$",$price);
        
$item_price $priceArray[1];
        
$item_bin $priceArray[1];
        
$item_bids strip_tags($ebayTDArray[7]);
        
$item_timeleft strip_tags($ebayTDArray[8]);

        echo 
$item_name." ".$item_price." ".$item_bids." ".$item_timeleft."<BR>";
    }
}
?>

page1 page2 page3


Comments:
Re: Completed listings
Posted 03/23/08 11:23AM by AceBHound
I don't have specifics on how to pass the password credentials to a site, but I know it's possible because there are programs and applications out there that are capable of doing this.
Completed listings?
Posted 12/24/06 3:26AM by Anonymous Techdoser
Is it possible to search through completed listings? So, is it possible to log-in (without the visitor of my site knowing the log-in/password) and extract these auctions as well?
Thanks!
Posted 04/23/06 12:27AM by Anonymous Techdoser
Thanks for writing this article. I appreciate all the work you've put into it and wanted to say IT WORKS! :O)

Best article with a working example I have ever found online!



If you have an account, please login below. You can sign up for a new account, it's free!
You can also post anonymously as Anonymous Techdoser if you leave the username/password fields blank.

*Username
*Password
Subject
Comment  
 




To verify you're a human please type the letters in the image above


*Due to URL spamming, comments will be approved before being posted.




Partners
Sony LCD TV
Read Reviews On Sony LCD TV's
Buy Desktop, Laptop & Netbook Computers online at Big Brown Box
Dish Network HD Programming
Quality resolution with HD from Dish.