GoScrapy aims to be a powerful web scraping framework in Go, inspired by Python's Scrapy framework. It offers an easy-to-use Scrapy-like experience for extracting data from websites, making it an ideal tool for various data collection and analysis tasks, especially for those coming from Python and wanting to try scraping in Golang..
Goscrapy requires Go version 1.22 or higher to run.
go mod init books_to_scrape
go install github.com/tech-engine/goscrapy@latest
Note: make sure to always keep your goscrapy cli updated.
goscrapy -v
goscrapy startproject books_to_scrape
This will create a new project directory with all the files necessary to begin working with GoScrapy.
\iyuioy\go\go-test-scrapy> goscrapy startproject books_to_scrape
🚀 GoScrapy generating project files. Please wait!
✔️ books_to_scrape\constants.go
✔️ books_to_scrape\errors.go
✔️ books_to_scrape\job.go
✔️ main.go
✔️ books_to_scrape\record.go
✔️ books_to_scrape\spider.go
✨ Congrates. books_to_scrape created successfully.
In your main.go
file, set up and execute your spider.
For detailed code, please refer to the sample code here.
package main
import (
"context"
"errors"
"fmt"
"os"
"os/signal"
"books_to_scrape/books_to_scrape"
"sync"
"syscall"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup
wg.Add(1)
spider, errCh := books_to_scrape.New(ctx)
go func() {
defer wg.Done()
err := <-errCh
if err != nil && errors.Is(err, context.Canceled) {
return
}
fmt.Printf("failed: %q", err)
}()
// trigger the Start Request
spider.StartRequest(ctx, nil)
OnTerminate(func() {
fmt.Println("exit signal received: shutting down gracefully")
cancel()
wg.Wait()
})
}
Please follow the wiki docs for details.
GoScrapy is not stable, so its API may change drastically. Please exercise caution when using it in production.
GoScrapy is available under the BSL with an additional usage grant that allows free internal use. Please ensure that you agree with the license before contributing to GoScrapy, as by contributing to the GoScrapy project, you agree to the terms of the license.
Cookie managementBuiltin & Custom Middlewares supportCss & Xpath Selectors- Logging
- Triggers
- Tests(work in progress)