Saturday May 18, 2024

Basic eBay Search Parsing

To use this script, simply call the PHP file and append "?searchstring=<text_you_want_to_search>" onto the URL. So, for instance -- "" 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
 This script is to demonstrate a technique to parse eBay auctions.

 Author: Wayne Eggert
 Last Updated: December 2004

$URL "".$searchstring."&sosortproperty=1&ht=1&from=R10&BasicSearch=";
$file fopen("$URL""r");
$r "";
$data fread($file8192);
$r .= $data;
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++){
strstr($ebayTABLEArray[$x],"Customize Display")){ // this is text
$resultTable $x+1;

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

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

$ebayTDArray preg_split ("/<td.*?>/",$ebayTRArray[$i]);
$item strip_tags($match[0],"<A></A>");
$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]);

$item_name." ".$item_price." ".$item_bids." ".$item_timeleft."<BR>";

page1 page2 page3

Anonymous Techdoser
Posted 01/18/13 2:37PM by Anonymous Techdoser
Possibly out of date for the new ebay, we will see. However, this is the BEST explanation of preg_split I have ever seen and I can see it's potential for many things. Many thanks
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?
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!