package me.kiwipop.scrape;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.jaunt.*;

import java.util.ArrayList;
import java.util.List;

public class DuckScrape {
    public static List<String> searchDuck (String keyword) {
        List<String> searchResults = new ArrayList<>();
        try{
            WebClient webClient = new WebClient(BrowserVersion.CHROME);
            HtmlPage page = webClient.getPage("https://duckduckgo.com/html/?q=" + keyword);
            List<HtmlAnchor> l = page.getByXPath("//a[@class='result__url']");
            for(HtmlAnchor a: l) {
                searchResults.add(a.getHrefAttribute());
            }


        }
        catch(Exception e){
            System.err.println(e);
        }
        return searchResults;
    }
}