|
|
|
Under the game board you will see this one. Look at PGN. Have two options. View is text format. Non-member can download one game at one time.

@msjenned: I'm actually more interested in getting lines of moves, by order of their popularity (as they are displayed on chessgame.com), not PGNs of individual games.
Thanks for the help, though. :)

Lol, I think I found a solution myself:
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
public class Test {
private static HtmlUnitDriver driver;
public static void main(String[] args) {
driver = new HtmlUnitDriver();
driver.get("http://www.chessgames.com/perl/explorer");
getMoves("http://www.chessgames.com/perl/explorer", new ArrayList<String>(), 0);
}
private static void getMoves(String back, List<String> prevmoves, int depth) {
List<WebElement> elementList = driver.findElements(By.xpath("//a"));
List<String> element_urls = new ArrayList<String>();
List<String> element_texts = new ArrayList<String>();
for (WebElement element : elementList) {
element_urls.add(element.getAttribute("href"));
element_texts.add(element.getText());
}
if (element_texts.get(1).equals("learn more")
|| !driver.getTitle().equals("Chess Opening Explorer")) {
printMoves(prevmoves);
return;
}
for (int i = 1 + depth; i < element_urls.size()
&& !element_texts.get(i).isEmpty(); i++) {
if (element_texts.get(i).equals("search database for this position"))
continue;
//System.out.println(element_texts.get(i));
prevmoves.add(element_texts.get(i));
String url = driver.getCurrentUrl();
driver.get(element_urls.get(i));
getMoves(url, prevmoves, depth + 1);
prevmoves.remove(prevmoves.size() - 1);
}
driver.get(back);
}
private static void printMoves(List<String> moves) {
String line = "";
for (String s : moves)
line += s + " ";
try {
BufferedWriter out = new BufferedWriter(new FileWriter("opening.txt", true));
out.write(line);
out.newLine();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Do any of you guys know if there's a way to download chessgame.com's database as a .pgn / .txt format?
Thanks.