Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 Forbidden but postman return 200 #831

Open
C-L-STARK opened this issue Nov 5, 2024 · 1 comment
Open

403 Forbidden but postman return 200 #831

C-L-STARK opened this issue Nov 5, 2024 · 1 comment

Comments

@C-L-STARK
Copy link

C-L-STARK commented Nov 5, 2024

https://pixabay.com/zh/photos/search/?order=ec&pagi=1

we want use colly to get some images from this website.
but we got 403; use postman return 200. why ?

package main

import (
	"strconv"

	"github.com/gocolly/colly"
)

func main() {
	c := colly.NewCollector(
		// MaxDepth is 2, so only the links on the scraped page
		// and links on those pages are visited
		colly.Async(true),
	)
	c.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60"
	c.Limit(&colly.LimitRule{DomainGlob: "*", Parallelism: 4})

	// Find and visit all links
	c.OnHTML("script", func(e *colly.HTMLElement) {
		if e.Attr("type") == "application/ld+json" {
			// parse inner content
			content := e.Text
			println(content)
		} else {
			println(e.Text)
		}
		e.Request.Visit(e.Attr("src"))
	})

	c.OnRequest(func(r *colly.Request) {
		println(r.URL.String())
	})

	c.OnError(func(r *colly.Response, e error) {
		println(r.StatusCode)
		println(e.Error())
	})

	for i := 1; i < 2; i++ {
		c.Visit("https://pixabay.com/zh/photos/search/?order=ec&pagi=" + strconv.Itoa(i))
	}

	c.Wait()
}
[Running] go run "~/pixabay_spider/main.go"
https://pixabay.com/zh/photos/search/?order=ec&pagi=1
403
Forbidden
@C-L-STARK
Copy link
Author

it seems like: the website use http2.0, but colly send http1.1;

how to set a http2 proxy ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant