I'm using requests module to retrieve content from the website kat.cr and here is the code I used:
try:
response = requests.get('http://kat.cr')
response.raise_for_status()
except Exception as e:
print(e)
else:
return response.text
At first the code works just fine and I could retrieve the website source code, but then it stopped and I keep receiving this message "404 Client Error: Not Found for url: https://kat.cr"
I tried fixing this issue with user-agent like this:
from fake_useragent import UserAgent
try:
ua = UserAgent()
ua.update()
headers = {'User-Agent': ua.random}
response = requests.get(url, headers=headers)
response.raise_for_status()
except Exception as e:
print(e)
else:
return response.text
But this doesn't seem to work either
Can you please help me fix this problem and thanks.