Advanced Topics

Searching the Web with GPAL.GoogleDorking

GPAL.GoogleDorking wraps the Google Custom Search API with the advanced search operators -- site, filetype, exact phrase, date range -- that make up a "Google dork", returning results into a grid for the rest of a workflow to use.

API Key and Search Engine

GPAL.GoogleDorking starts the chain with WithApiKey(apiKey), which validates the key's format before continuing. WithEngineId selects a Google Custom Search Engine ID to search with. GPAL.GoogleDorkingFor(apiKey, engineId) is a shorthand that sets up both in one call for the common case of reusing the same key and engine throughout a workflow. If you don't have a key yet, WithCredentials plus WithProjectName/WithProjectId and GenerateApiKey(out apiKey) can create one through a connected Google Cloud project.

var dorking = GPAL.GoogleDorkingFor("AIza...", "017576662512468239146:omuauf_lfve");

Building a Query

Before running a search, you can narrow the results with any combination of standard Google search operators: restrict to a specific domain, require a particular file type, exclude a term, or require the search term to appear in the page title or URL. Date range and sort order round out the query. Once the operators are set, a single call triggers either a normal keyword search or an exact-phrase search.

dorking

.WithSite("example.com")

.WithFileType(FileType.Pdf)

.WithDateRestriction(DateRestriction.PastYear)

.SearchFor("quarterly report");

Reading Results

GetResults(out results) runs the search and fills an IGPALGrid<string> with one row per result, each containing the title, link, and snippet fields requested from the API. WithResultsPerPageUpTo10 caps how many results come back per call (Google Custom Search returns at most 10 per request). Because GetResults returns IAllowDorkingQueryBuilding, the same dorking object can immediately start a new query with different terms.

dorking

.WithResultsPerPageUpTo10(10)

.SearchFor("site:example.com quarterly report filetype:pdf")

.GetResults(out IGPALGrid<string> results);

foreach (var row in results)

Console.WriteLine($"{row[0]} -> {row[1]}");