Advertisement
dereksir

Untitled

Feb 22nd, 2024
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.61 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "net/http"
  6.     "github.com/PuerkitoBio/goquery"
  7. )
  8.  
  9. func main() {
  10.     // URL to make the HTTP request to
  11.     url := "https://scrapeme.live/shop"
  12.  
  13.     // Make the GET request
  14.     resp, _ := http.Get(url)
  15.     defer resp.Body.Close()
  16.  
  17.     // Use goquery to parse the HTML
  18.     doc, _ := goquery.NewDocumentFromReader(resp.Body)
  19.  
  20.     // Extract names of Pokémon
  21.     var pokemonNames []string
  22.     doc.Find("h2").Each(func(i int, s *goquery.Selection) {
  23.         pokemonNames = append(pokemonNames, s.Text())
  24.     })
  25.  
  26.     // Print the extracted Pokémon names
  27.     for _, name := range pokemonNames {
  28.         fmt.Println(name)
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement