NodeJS + Request - Access denied when requesting website

后端 未结 1 535
既然无缘
既然无缘 2021-01-12 13:33

I\'m trying to request the html of a website using request but I keep getting an access denied error. How do I get past this? Here is the code for the function below:

<
相关标签:
1条回答
  • 2021-01-12 13:49

    You are getting a 403 Forbidden because that website is blocking all requests sent using non common user agents (basically they check User-Agent header). It is a very simple protection to avoid scrappers.

    For example, if you send the following cURL using its standard User-Agent, the response is received perfectly:

    curl -v 'https://www.jdsports.co.uk/product/green-nike-vapormax/281735/'
    

    Nevertheless, if you repeat that request specifying a non existing User-Agent, the request is blocked:

    curl -v 'https://www.jdsports.co.uk/product/green-nike-vapormax/281735/' -H 'User-Agent: StackOverflow'
    
    0 讨论(0)
提交回复
热议问题