Getting Started with the Code in This Book

One of the ways eBay Hacks is different from other eBay books you might’ve read is that the solutions contained herein are not limited to the features available on the eBay web site. Rather, the hacks in this book make use of other websites, third-party software tools, and programming code you can type in, customize, and run yourself.

Tip

You don’t have to type any of the code in this book by hand! Just go to ebayhacks.com, click The Hacks, and select the hack or section in which the code appears.

Some of this code is simple, requiring no prior experience and only a little patience. Depending on the task at hand, though, some other code examples may require some programming experience and a larger amount of the aforementioned patience. (Each hack is adorned with a little thermometer to indicate its complexity, as described in “Conventions Used in This Book,” later in this preface.) What follows is a little background on the languages and concepts used in the hacks that employ code.

eBay’s home is the Web, a heterogeneous place governed by well-defined standards. In most cases, the concepts presented in this book work with any programming language or platform you might be using with your web site. However the example code is primarily kept to three language and platform combinations, each inhabiting its own niche of the Internet ecology: HTML for creating web content, JavaScript for adding interactivity to web pages, and Perl for server-side (CGI) scripting. Programming for the eBay API is a somewhat different animal and is discussed in the introduction to Chapter 8.

HTML

HTML (Hypertext Markup Language) isn’t so much a programming language as a schema used to add formatting to plain text. As a seller on eBay, you use HTML tags to dress up your auction descriptions and to create web content.

You don’t need to be proficient in HTML to start using it; see “Format the Description with HTML” [Hack #52] for an introduction and crash course. The more HTML you know, the more of it you can employ to enhance your listings.

JavaScript

JavaScript is a scripting language (not to be confused with the Java programming language) used to add interactivity to otherwise-static web pages. For instance, when you click thumbnail photos in some eBay auctions to view their larger versions right on the same page, you’re running JavaScript code embedded in the auction page. JavaScript comes in handy if you want to construct an interactive photo album [Hack #79] with photos hosted on your own server [Hack #76] , for example.

JavaScript code is placed within <script></script> tags on an HTML-formatted web page, such as the description in an eBay listing. When someone views your auction, the JavaScript code is executed by the browser client (e.g., Internet Explorer, Mozilla Firefox), which is why it’s categorized as client-sidescripting.

Tip

If you want to use the same JavaScript code in all your eBay listings, you can place the code in a file on your web server (say, scripts.js), and then merely reference it by placing the following line in your listing descriptions:

<script src="http://www.your.server/scripts.js"> </script>

where http://www.your.server/your-scripts.js js the full URL of your scripts.js file. Any JavaScript code in this book that appears inside a <script></script> structure can be used in this way; just remove the opening <script><!--and closing --></script> tags, and you’re good to go!

eBay imposes some restrictions on the use of JavaScript in listing descriptions, presumably in an effort to reduce the risk of abuse. Among the more useful JavaScript elements specifically prohibited in descriptions are the window. open statement and eval() function. If you try to submit a listing containing one of these prohibited statements, you’ll get this confusing and largely inaccurate error message:

Your listing cannot contain javascript (“.cookie”, “cookie(“, “replace(“, IFRAME, META, or includes), cookies or base href.

Although none of the code in this book uses these forbidden statements, it is entirely possible that eBay may have introduced additional restrictions by the time you read this. As with all the code in eBay Hacks, be sure to visit ebayhacks.com for any applicable corrections, updates, or workarounds.

Tip

If you’re using Firefox or Mozilla, you can use the JavaScript Console to see error messages and warnings generated by your JavaScript code as you test it. To open the JavaScript Console window, type javascript: (including the colon) in the address bar and press Enter. If you’re using Internet Explorer, you can get something similar by downloading the Microsoft Script Debugger (available for free from www.microsoft.com/downloads/).

Note that there are other ways to add interactivity to web pages, such as VBScript, Java, and (now deprecated) ActiveX controls, but none are as widely supported and seamless as JavaScript.

Perl

In order to show up-to-date information on a web page, such as the current price and the amount of time left on an eBay auction page, its content must be dynamically generated. In most cases, this is done by a program on the web server before the page is sent to the browser. Although just about any programming language is capable of generating web content, most of the hacks in this book use Perl for this purpose. See the “Using CGI Scripts” sidebar for details.

Perl (Practical Extract and Report Language) is a great choice for “server-side” scripting because it’s simple, easy to learn, requires no expensive or complicated development environment, and works on any computing platform. If you’re using Unix, Linux, or Mac OS X, Perl is almost certainly already installed on your system. If you’re using Windows, you can get ActiveState’s ActivePerl for free at www.activestate.com/Products/ActivePerl/.

Tip

Some hacks in this book require the use of Perl modules, extensions to the Perl language that add functionality you’d otherwise have to program from scratch. See the “Installing Perl Modules” sidebar for details.

Perl scripts are simply text files; you can edit them with any plain-text editor, such as Notepad in Windows or emacs in Unix. (Note that word processors, such as Word and Wordperfect are not suitable for this task, as they’ll jumble up the text file with proprietary formatting data.)

To run a Perl script in Windows, as long as filename has the .pl file extension,* you can double-click the file icon to start Perl and execute the script. If the script provides text output, you’ll want to run it from a Command Prompt window (Start Run cmd.exe) instead; just go to the folder containing the script (type cd foldername), type the name of the script file, and press Enter.

To run a Perl script in Unix, Linux, or Mac OS X, open a terminal window, go to the folder containing the script (cd foldername), type ./scriptfilename (where scriptfilename is the filename of the script), and press Enter.

If you want to learn more about Perl, the book to get is Programming Perl, Third Edition (also known as the “Camel Book”) by Larry Wall, Tom Christiansen, and Jon Orwant.

Get eBay Hacks, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.