Example

Login Example πŸ‘¨πŸΎβ€πŸ’»

Introduction πŸ“š

In this example, we will walk you through a simple login scenario using Go-Ski. This example is designed to provide a detailed understanding of how to use various features of Go-Ski for web scraping. The complete example code is located in the examples folder and the file is named login_example.go.

Breaking Down the Code πŸ“

Step 1: Import Required Packages

First, we import the necessary Go packages. Time is used specifically for creating delays in formSubmit actions and also sleep actions.

import (
"context"
"time"
"github.com/barfieldlabs/go-ski/core"
"github.com/chromedp/cdproto/target"
)

Step 2: Initialize Procedures

Here, we initialize a new Procedures object with GUI enabled.

proc := core.NewProcedures(true)

Step 3: Define Actions

We define a list of actions to navigate to the login page, sleep, submit a form, click a button, switch to an iframe, and finally scrape some data. View all the actions in the API Reference.

proc.Actions = []core.Action{
{
Type: core.Navigate,
URL: "https://example.com/login",
},
// ... other actions
}

Step 4: Create a Context

We create a new context for our web scraping tasks.

ctx := context.Background()

Step 5: Execute Actions

Finally, we execute the actions using the Execute method of the Procedures object.

err := proc.Execute(ctx, targetInfo)
if err != nil {
panic(err)
}

Running the Example πŸƒβ€β™‚οΈ

To run this example, navigate to the examples folder and execute:

go run login_example.go

Conclusion πŸŽ‰

Congratulations! You've successfully walked through a login example using Go-Ski. Feel free to modify this example to suit your specific needs. Pretty simple right? Go-Ski is built to be simplistic and easy to use, with the goal of making web scraping more streamlined and structured.

For the complete example, you can check out the login_example.go (opens in a new tab) file.