-
Notifications
You must be signed in to change notification settings - Fork 0
/
survey.go
55 lines (43 loc) · 1.15 KB
/
survey.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"context"
"flag"
"fmt"
"log"
"time"
"github.com/chromedp/chromedp"
)
func main() {
// Define a command-line flag for the URL
url := flag.String("u", "", "URL to open")
flag.Parse()
// Ensure the URL is provided
if *url == "" {
log.Fatal("URL must be provided using the -u flag")
}
// Create a new context for ChromeDP
ctx, cancel := chromedp.NewContext(context.Background())
defer cancel()
// Run the tasks
var res string
err := chromedp.Run(ctx, chromedpTasks(*url, &res))
if err != nil {
log.Fatal(err)
}
// Print the resulting page content
fmt.Println(res)
}
func chromedpTasks(url string, res *string) chromedp.Tasks {
return chromedp.Tasks{
// Navigate to the provided URL
chromedp.Navigate(url),
// Wait for the "Next" button to be visible
chromedp.WaitVisible(`#next_button`, chromedp.ByID),
// Click the "Next" button
chromedp.Click(`#next_button`, chromedp.ByID),
// Wait for the page to load after clicking
chromedp.Sleep(2 * time.Second), // You can adjust the sleep duration as needed
// Get the HTML content of the page after clicking "Next"
chromedp.OuterHTML("html", res),
}
}