package main
import (
"context"
"log"
"time"
"github.com/chromedp/chromedp"
)
func main() {
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
var buf []byte
if err := chromedp.Run(ctx,
chromedp.Navigate("https://example.com"),
chromedp.CaptureScreenshot(&buf),
); err != nil {
log.Fatal(err)
}
if err := chromedp.Cancel(ctx); err != nil {
log.Fatal(err)
}
if err := chromedp.Wait(ctx); err != nil {
log.Fatal(err)
}
log.Println("Capture successful!")
// do something with the screenshot data in 'buf'
}
package main
import (
"context"
"fmt"
"log"
"strings"
"time"
"github.com/chromedp/chromedp"
)
func main() {
endpoints := []string{"https://shitflare.asia/?pagee=1", "https://shitflare.asia/?pagee=2", "https://shitflare.asia/?pagee=3"}
for _, endpoint := range endpoints {
fmt.Printf("Opening page: %s\n", endpoint)
if err := openWebPage(endpoint); err != nil {
log.Fatal(err)
}
time.Sleep(2 * time.Second) // Wait for some time before opening the next page
}
}
func openWebPage(endpoint string) error {
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
// Create a buffer to capture a screenshot
var buf []byte
options := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.Flag("headless", false), // Run in visible mode
chromedp.Flag("disable-gpu", true),
chromedp.Flag("mute-audio", true),
chromedp.WindowSize(1920, 1080), // Set a custom window size if needed
)
allocatorContext, cancelAllocator := chromedp.NewExecAllocator(context.Background(), options...)
defer cancelAllocator()
ctx, cancel = chromedp.NewContext(allocatorContext)
defer cancel()
// Open the webpage and capture a screenshot
if err := chromedp.Run(ctx,
chromedp.Navigate(endpoint),
chromedp.CaptureScreenshot(&buf),
); err != nil {
return err
}
// Save the captured screenshot to a file (optional)
filename := strings.ReplaceAll(endpoint, "https://", "")
filename = strings.ReplaceAll(filename, "http://", "")
filename = strings.ReplaceAll(filename, "/", "_") + ".png"
if err := saveScreenshotToFile(buf, filename); err != nil {
return err
}
fmt.Printf("Screenshot saved to: %s\n", filename)
return nil
}
func saveScreenshotToFile(buf []byte, filename string) error {
return chromedp.SaveScreenshot(filename, buf)
}
In this script, we iterate through the provided endpoints and open each one using the openWebPage function. It captures a screenshot of each page, saves it to a file (optional), and then waits for 2 seconds before opening the next page. Adjust the sleep duration as needed.
To run the script, save it as a .go file (e.g., script.go), and execute it using the Go compiler:
Make sure that you have the chromedp library installed via go get -u github.com/chromedp/chromedp. Additionally, you will need to have a Chrome or Chromium installation on your system for the script to work.