Returning 403 Forbidden from simple get but loads okay in browser

前端 未结 2 1935
执笔经年
执笔经年 2020-12-11 23:14

I\'m trying to get some data from a page, but it\'s returning the error [403 Forbidden].

I thought it was the user agent, but I tri

2条回答
  •  暖寄归人
    2020-12-11 23:44

    The site could be using anything in the request to trigger the rejection.

    So, copy all headers from the request that your browser makes. Then delete them one by one1 to find out which are essential.

    As per Python requests. 403 Forbidden, to add custom headers to the request, do:

    result = requests.get(url, headers={'header':'value', })
    

    1A faster way would be to delete half of them each time instead but that's more complicated since there are probably multiple essential headers

提交回复
热议问题