Monday, January 10, 2011

Assessing prices on eBay

I recently listed my old iPhone for sale on eBay. I wanted to know how much phones were going for. But I didn't just want to peruse the prices; I wanted to plot them and analyze them. Here are the steps I took. They are ugly, but they worked on my system, which is Mac OS X Leopard, Firefox 3, and the Table2Clipboard extension (which you don't really need). I'm interested to hear about better ways to do this.

Do an eBay search.
  • search text: iphone 3gs 32
  • Preferences: Completed listings
  • Preferences: Used
  • show 200 results

Copy results to a local file
  • create dedicated directory like /Users/exampleUser/ebaySoldPrice
  • copy results tables only:
  • select a word in the first listing
  • from the right click menu, choose table2clipboard/select table
  • scroll to end of page,
  • shift click in last item to extend selection to include all items,
  • right click and choose View selection source
  • it takes a while for this window to populate
  • Copy, paste and save text as "ebay_search_results.txt"


Clean up the results
  • Open a terminal window and type the following commands (you may have to fix line breaks if you copy this text)

    • cd /Users/exampleUser/ebaySoldPrice/


    • cat ebay_search_results.txt  | sed 's/~//g' | 
      sed 's/<table class="li" r="/~/g' |
      tr "~" "n" | sed 's/ shipping.*$//' |
      sed 's/([0-9]*).*class="vip">/1~/' |
      grep Sold | sed 's/<[^$]*$/~/' |
      sed 's/Free shipping/$0/' | sed 's/<[^$]*$/~/' |
      sed 's/<.*$/~na/' | tr "~" "t"
      >ebay_search_results_cleaned.txt



here's how that breaks down:
  • sed s'/\~//g'
                    ### remove any tildes in ad title
  • tr  "~" "\n"
                    ### replace tildes with newline
  • sed 's/<table class="li" r="/~/g'
                    ### replace table starts with tildes
  • sed 's/ shipping.*$//'
                    ### get rid of text after shipping
  • sed 's/\([0-9]*\).*class\=\"vip\"\>/\1\~/' |
                    ### keep the initial row number, deletes everything else until the title
  • grep Sold
                    ### limit to items that sold
  • sed 's/\<[^$]*\$/~/'  |
                    ### delete text between title and price
  • sed 's/Free shipping/\$0/'
                    ### give free a numerical value
  • sed 's/\<[^$]*\$/~/'  |
                    ### delete text between price and shipping price
  • sed 's/<.*$/~na/'
                    ### if price doesn't have a dollar amount, delete text and give it an NA value
  • tr "~" "\t"
                    ### replace tildes with tabs
  • >ebay_search_results_cleaned.txt
                    ### direct the output into a file

No comments: