Web scraping from TypeScript or JavaScript with the Scrapfly SDK (`scrapfly-sdk`). Use when the user asks to scrape a URL, bypass anti-bot protection, render...
浏览器
Scrapfly SDK Go
试用Web scraping from Go with the Scrapfly SDK (`github.com/scrapfly/go-scrapfly`). Use when the user asks to scrape a URL, bypass anti-bot protection, render Ja...
它能做什么
Web scraping from Go with the Scrapfly SDK (`github.com/scrapfly/go-scrapfly`). Use when the user asks to scrape a URL, bypass anti-bot protection, render JavaScript, capture screenshots, or extract structured data from a Go program.
技能文档
Scrapfly Go SDK
Use the go-scrapfly module to scrape web pages from Go with proxy rotation,
anti-bot bypass (ASP), JavaScript rendering, screenshots, and AI extraction.
It ships a built-in goquery selector for parsing the response.
When to use
- Scraping web pages (HTML, JSON, text, markdown) from a Go codebase
- Bypassing anti-bot protections (Cloudflare, DataDome, PerimeterX, Kasada)
- Rendering JavaScript-heavy pages with a headless browser
- Capturing screenshots or extracting structured data
Setup
go get github.com/scrapfly/go-scrapfly
export SCRAPFLY_API_KEY="your-api-key"
The package name is scrapfly. Get your API key at scrapfly.io.
Basic scrape
package main
import (
"fmt"
"log"
"os"
"github.com/scrapfly/go-scrapfly"
)
func main() {
client, err := scrapfly.New(os.Getenv("SCRAPFLY_API_KEY"))
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
apiResponse, err := client.Scrape(&scrapfly.ScrapeConfig{
URL: "https://web-scraping.dev/product/1",
})
if err != nil {
log.Fatalf("scrape failed: %v", err)
}
fmt.Println(apiResponse.Result.Content)
}
Anti-bot bypass, geo-targeting, JS rendering
ScrapeConfig fields are Go-idiomatic PascalCase. ProxyPool takes a typed
constant.
apiResponse, err := client.Scrape(&scrapfly.ScrapeConfig{
URL: "https://web-scraping.dev/product/1",
ASP: true, // bypass anti-bot
Country: "us", // proxy country (ISO 3166-1 alpha-2)
ProxyPool: scrapfly.PublicResidentialPool, // or scrapfly.PublicDataCenterPool
RenderJS: true, // headless browser rendering
WaitForSelector: "div.product", // requires RenderJS
RenderingWait: 5000, // ms, requires RenderJS
Format: "markdown", // raw | clean_html | json | markdown | text
})
Built-in HTML selector
selector, err := apiResponse.Selector() // goquery document
if err != nil {
log.Fatal(err)
}
fmt.Println("Title:", selector.Find("h3").First().Text())
Screenshots and extraction
shot, err := client.Screenshot(&scrapfly.ScreenshotConfig{
URL: "https://web-scraping.dev/products",
})
data, err := client.Extract(&scrapfly.ExtractionConfig{
Body: []byte(apiResponse.Result.Content),
ContentType: "text/html",
ExtractionPrompt: "extract all product names and prices",
})
Important notes
RenderJS: trueis required forRenderingWait,WaitForSelector, and screenshotsscrapfly.PublicResidentialPoolis recommended alongsideASP: true- Use
Format: "markdown"for clean, LLM-friendly content - Read the page body via
apiResponse.Result.Content; parse withapiResponse.Selector()
相关技能
Web scraping using the Scrapfly Scraper API with the Python SDK
Crawl entire websites using the Scrapfly Crawler API with the Python SDK
Use the Scrapfly CLI (`scrapfly`) to scrape web pages, capture screenshots, extract structured data with AI, crawl entire sites, and drive a cloud browser ov...
Capture web page screenshots using the Scrapfly Screenshot API with the Python SDK
Extract structured data from web content using the Scrapfly Extraction API with the Python SDK