Three search terms, three pages each, nine calls, one JSON array out. The browser visits the homepage once to earn a session and never touches the DOM again.
using GenerallyPositive;
using GenerallyPositive
using static GenerallyPositive
GPAL
// declared once and reused, the same way a Selector is
GPALRequest searchRequest = (GPALRequest)GPAL
// one row per search, one column per token
IGPALGrid<string> searchTerms = GPAL
searchTerms
searchTerms
searchTerms
IBrowser browser = GPAL
string json = null;
browser
browser
GPAL
Going straight at an inner path or the API gets refused. The cookies that clear an anti-bot check are only set by a real navigation, so the workflow visits the homepage first and lets the site hand them over. After that the browser never reads an element again.
browser
A fetch issued before any navigation has no session behind it and will read like a bare HTTP client. If the site would block curl, it will block this too.
GPAL.Request describes an API call the way a Selector describes an element. Path, method, content type, body and headers are stated once, given a name, and reused for every row. Nothing about it is tied to a particular search.
GPALRequest searchRequest = (GPALRequest)GPAL
A path on the site's own domain is a same origin request, so the session the browser earned is all it needs and there is no CORS preflight to think about. A body sent as form-urlencoded rather than JSON keeps it that way.
The numbered markers in the body match the columns of the grid: {0} is the first column, {1} the second. GPAL does not parse the payload and does not care whether it is JSON, a form or a query string. Where a marker goes and what the payload is are entirely the workflow's business.
// one row per search, one column per token
searchTerms
WithPageToken names the marker GPAL fills in itself, WithFirstPage says what the site counts from, and WithPages says how many calls to make per row. Everything else in the body is the row's business. Three rows and three pages is nine requests, issued in the order asked for.
browser
SaveTo hands back one JSON array holding every response body, every row's pages, in the order requested. From there it is a normal GPALConverter job: to a file, to a class, to a grid, to a database.
string json = null;
browser
GPAL
CallAfterFetch fires once per response, so a long run reports as it goes rather than at the end. The callback is declared on the request, alongside everything else about it.
//
static void ReportSearch(string response)
{
GPAL
}
You can, and the next tutorial shows how. The difference is what travels. Fetch runs inside the page, so it carries the cookies, the user agent, the header order and the TLS handshake, all of it. A client outside the browser carries what can be handed over, which is everything except the transport. Where a site's wall is the cookie jar, both work. Where the wall inspects the TLS fingerprint, only the fetch gets through.
Running the same request both ways and comparing the answers tells you which wall a site is actually using. If the handed-over client gets a deny page and the in-page fetch gets data, the site is fingerprinting the transport rather than checking a cookie.
Showing off some plain text in these paragraphs eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quo veniam mollitia excepturi animi eum illum non libero sapiente provident assumenda, delectus voluptatum nobis sed dolorem adipisci laudantium incidunt. Error, ratione?
Here you can find different accents and emphasis sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
This is a link and how it could look like bestlinkinthebeautifulworld. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Here's just some classic bold text adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam notBoldSecondbestlinkinthebeautifulworld illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at adipisicing elit libero vel voluptas? Expedita, adipisicing facere dolores voluptatem ad ab rem assumenda soluta!
Other cuple of colors in case we want to emphasize several ways adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam adipisicing elit illo nostrum corporis at voluptatem libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta! Lorem ipsum dolor, sit amet consectetur adipisicing elit. Quod veniam, quam ad expedita laborum sed at voluptates culpa ipsam ut vel. Ullam temporibus a mollitia quod aliquam ratione exercitationem nesciunt.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Obcaecati, iste distinctio veritatis eligendi laboriosam illo nostrum corporis at libero vel voluptas? Expedita, facere dolores voluptatem ad ab rem assumenda soluta!
Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae quas consequuntur illo numquam assumenda autem exercitationem distinctio perspiciatis in natus. Eius dicta similique ipsam ipsa minima, nemo quae enim tempore.
GPAL
.CallIfNotFound(GenericCallIfNotFound)
.WithPublishToConsole();
//System.Drawing.Rectangle windowSize = new System.Drawing.Rectangle(10, 10, 1500, 1024);
// NOTE: we have to set browser = before we execute any steps
// this is due to the 'GenericCallIfNotFound' which might throw an exception, and BankScraper will not have the browser set when it calls scraper.Close()
// until the complete fluent line gets executed (meaning every step, meaning browser is not set until everything else succeeds)
browser = GPAL.Browser
.WithBrowserType(Enums.BrowserType.Chrome)
.WithProfileDataDirectory(ChromeProfileLocation)
.WithUseAutomationEngine(AutomationEngine.Selenium)
.WithWindowSize(new System.Drawing.Rectangle(0,0,1920,1080))
.ToGPALObject();