how can i get website html code using requests?

38 Views Asked by At

I repeated all the steps as in the tutorial but I don’t get the code. Although a couple of days ago everything worked

I write a simple code:

import requests
url = 'https://i-teka.kz/almaty/spisokaptek'
page = requests.get(url)
print(page.text)

and after running i get:

<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

but should get the full html code I don't understand what the problem is

1

There are 1 best solutions below

0
shashstormer On BEST ANSWER

The may be checking for various headers. You can try various headers and find the required headers.

or

There is a library called requestez which simplifies all this and does it automatically. you can do

pip install requestez

and then

import requestez
url = 'https://i-teka.kz/almaty/spisokaptek'
page = requestez.Session().get(url)
print(page)

image of output

part of the html of the page