LoveTech Bots

LoveTech eBay Bots

Summary

Selenium WebDriver makes it easy to crawl sites like eBay. LoveTech has assembled the following convenience methods to make it easier to get started crawling eBay

Install Selenium WebDriver

Download Eclipse: https://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/mars2

Download Java jdk: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Download ChromeDriver.exe: https://sites.google.com/a/chromium.org/chromedriver/downloads

Download Selenium Java jar: http://www.seleniumhq.org/download/

Download JSON jar: https://mvnrepository.com/artifact/org.json/json/20170516

Common Bot Methods

These common methods are used by many of our bots:

public static String runJavascript(WebDriver driver, String script) {
	WebElement body = driver.findElement(By.cssSelector("body"));
	return (String)((JavascriptExecutor)driver).executeScript(script, body);
}

Ebay Bot:

import java.io.File;
import java.io.PrintWriter;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class EbayBot {

	public static void main(String[] args) throws InterruptedException, JSONException {
		System.setProperty("webdriver.chrome.driver", "C:/Selenium/chromedriver.exe");
		searchEBay(driver, "Phil Ochs Autograph");
		loadjQuery(driver);
	}
	private static void searchEBay(WebDriver driver, String query) {
		runJavascript(driver, "$('.search-input').val('" + query + "');$('button.nav-search').click()");
	}
	
	public static void ebayLogin(WebDriver driver, String username, String password, Boolean logoutFirst) {
		if(logoutFirst) {
			driver.get("https://ebay.com/logout");
		}
		driver.get("https://ebay.com/login");
		//System.out.println("$('input.email-input').val('" + username + "');$('input[type=\"password\"]').val('" + password + "');$('button[type=\"submit\"]').click()");
		runJavascript(driver, "$('input.email-input').val('" + username + "');$('input[type=\"password\"]').val('" + password + "');$('button[type=\"submit\"]').click()");
	}

	//See Common Bot Methods
}

Explore Chakra7 Today