The problem is this: from the browser the site opens with a bang, but when you send it a get request using requests, it returns error 403. What could be the problem?

import requests r = requests.get("http://<тут адрес сайта>") 

And this happens only with this site (hltv.org). Does it have some kind of protection?

  • 2
    use headers from any browser, without it, the site determines that the program works and blocks it - danilshik
  • @danilshik and how to form them? - Alexey
  • @danilshik {'user-agent': 'your-own-user-agent / 0.0.1'} I put it in here and it worked! Thank! - Alexey
  • I did not have time to add a comment) - danilshik

2 answers 2

As an example, the user-agent list can be found on the Internet, or simply copied from your browser.

 headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0' } r = requests.get(url_page, headers=headers) 

    It is necessary to imitate the input of a person, some sites block import requests

     headers = {'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/67.0.3396.99 Safari/537.36', 'Accept-Encoding': 'identity'} r = requests.get("https://www.hltv.org/", headers=headers) print(r) #<Response [200]>