Hi I’m trying to get a HTML code of page on my pc o get it but on pythonanywhere i see errors.
import requests
url = ‘https://example.com’
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', # User-Agent dla Chrome
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'
}
try:
response = requests.get(url, headers=headers) # Pobieranie strony
response.raise_for_status()
print(response.text)
except:
requests.exceptions.RequestException as e:
print("Error")
Please describe te solution od thia problem. Thx in advance.
New contributor
user25037967 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.