<commit_before>import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class Fetcher {

    private static WebDriver browser;

    public static void main(String[] args) {
        try {
            browser = new ChromeDriver();
            Config config = readConfig();
            List<String> results = fetchData(config.targets);
            writeResults(results);
        } catch (Exception e) {
            System.out.println("The program will exit due to a fatal error: " + e.getMessage());
            System.out.println("\nDebug details: " + e.getStackTrace());
        } finally {
            if (browser != null)
                browser.quit();
        }
    }

    private static void writeResults(List<String> results) {
        if (results.size() == 0) {
            System.out.println("No results.");
        } else {
            for (String result : results)
                System.out.println(result);
        }
    }

    private static List<String> fetchData(List<Target> targets) {
        List<String> fetched = new ArrayList<>(targets.size());
        for (Target target : targets) {
            String data = navigateAndExtract(target.url, target.selector);
            fetched.add(data);
        }
        return fetched;
    }

    private static Config readConfig() throws IOException {<commit_msg>export results to file, instead of screen/stdout<commit_after>import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class Fetcher {

    private static WebDriver browser;

    public static void main(String[] args) {
        try {
            browser = new ChromeDriver();
            Config config = readConfig();
            List<String> results = fetchData(config.targets);
            export(results);
        } catch (Exception e) {
            System.out.println("The program will exit due to a fatal error: " + e.getMessage());
            System.out.println("\nDebug details: " + e.getStackTrace());
        } finally {
            if (browser != null)
                browser.quit();
        }
    }

    private static void export(List<String> results) {
        if (results.size() == 0) {
            System.out.println("No results.");
        } else {
            //writeToScreen(results);
            writeToFile(results);
        }
    }

    private static void writeToFile(List<String> results) {
        try {
            Path file = Paths.get("fetched.txt");
            Files.write(file, results, Charset.forName("UTF-8"));
        } catch (IOException e) {
            System.out.println("Could not write results to file: " + e.getMessage());
        }
    }

    private static void writeToScreen(List<String> results) {
        for (String result : results)
            System.out.println(result);
    }

    private static List<String> fetchData(List<Target> targets) {
        List<String> fetched = new ArrayList<>(targets.size());
        for (Target target : targets) {
            System.out.println("Target: " + target.url);
            String data = navigateAndExtract(target.url, target.selector);
            fetched.add(data);
        }
        return fetched;
    }

    private static Config readConfig() throws IOException {
{'fraction_non_alphanumeric': 0.11526794742163801, 'fraction_numerical': 0.0007583417593528817, 'mean_word_length': 2.4200518582541055, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5186762', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1085, 'n_words': 265}