не могу найти правильное сжатие для этой веб-страницы (python requests.get)

Я могу загрузить эту веб-страницу в Google Chrome, но не могу получить к ней доступ через requests. Есть идеи, в чем проблема сжатия?

Код:

      import requests


url = r'https://www.huffpost.com/entry/sean-hannity-gutless-tucker-carlson_n_60d5806ae4b0b6b5a164633a'
headers = {'Accept-Encoding':'gzip, deflate, compress, br, identity'}

r = requests.get(url, headers=headers)

Результат:

      ContentDecodingError: ('Received response with content-encoding: gzip, but failed to decode it.', error('Error -3 while decompressing data: incorrect header check'))

2 ответа

Используйте пользовательский агент, эмулирующий браузер:

      import requests

url = r'https://www.huffpost.com/entry/sean-hannity-gutless-tucker-carlson_n_60d5806ae4b0b6b5a164633a'
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}

r = requests.get(url, headers=headers)

Вы получаете 403 Forbidden ошибка, которую вы можете увидеть, используя requests.head. Используйте предложение RJ Adriaansen , чтобы победить блокировку роботов huffpost.

      >>> requests.head(url)
<Response [403]>
Другие вопросы по тегам