Fiz esse código abaixo para teste, tentei baixar o logo do site Atacadão: Saída = 403 Forbidden
from urllib.error import HTTPError, URLError
from urllib.request import urlretrieve, Request, urlopen
from bs4 import BeautifulSoup
url = 'https://www.atacadao.com.br/?utm_cd1=TNT_TNT-Local_Campaigns_Atacadao-202112_Consideration_Website' \
'-Traffic_PSL_GoogleAds_Text-Ads_None_T_Atacadao_Atacadao_ALL_CPC_Atacadao_2021-01-24&utm_cd2=TNT_TNT' \
'-Local_Campaigns_Atacadao-202112_Consideration_Website-Traffic_PSL_GoogleAds_Text' \
'-Ads_None_T_Atacadao_Atacadao_ALL_CPC_Atacadao_2021-01-24&gclid=Cj0KCQjw8O' \
'-VBhCpARIsACMvVLOxYhTBcNNdhMOgboZmQu24YbPhru9ZZNAYJ2w1_33DkU-2k7jdzVYaAo0iEALw_wcB '
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/103.0.0.0 Safari/537.36'}
try:
req = Request(url, headers=headers)
response = urlopen(req)
html = response.read()
soup = BeautifulSoup(html, 'html.parser')
logo = soup.find('img', {'class': 'logo'})
urlretrieve(logo.get('src'), 'logo_atacadao')
except HTTPError as e:
print("O erro foi", e.status, e.reason)
except URLError as e:
print(e.reason)