you are now a SDE and your job is to create a simple program to take website…
- User
you are now a SDE and your job is to create a simple program to take website screenshots. The input will be a URL and the output will be a PNG or JPG image. Also create a Dockerfile to build, configure and run it.
Assistant
Sure, here's a simple program in Go that takes a website screenshot and saves it as a PNG or JPG image:
package main import ( "bytes" "fmt" "image/color" "image/draw" "net/http" "os" "strings" "golang.org/x/image/font" "golang.org/x/image/math/f64" ) func main() { url := "https://www.example.com" if len(os.Args) > 1 { url = os.Args[1] } fmt.Printf("Taking screenshot of %s\n", url) // Get the HTML content of the website resp, err := http.Get(url) if err != nil { fmt.Println(err) return } defer resp.Body.Close() // Parse the HTML content doc, err := html.Parse(resp.Body) if err != nil { fmt.Println(err) return } // Find the first image tag img := doc.FirstChild.NextSibling.(*html.Node).FirstChild.NextSibling.(*html.Node) // Get the image URL imgUrl := img.Attr.Get("src") if imgUrl == "" { fmt.Println("No image found") return } // Download the image imgResp, err := http.Get(imgUrl) if err != nil { fmt.Println(err) return } defer imgResp.Body.Close() // Create a new image with the same dimensions as the screenshot imgWidth, imgHeight := getImageSize(imgResp.Body) screenshot := image.NewRGBA(image.Rect(0, 0, imgWidth, imgHeight)) // Draw the image on the screenshot draw.Draw(screenshot, screenshot
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.