Search code examples
pythonweb-scrapinghtml-parsing

how can i get website html code using requests?


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


Solution

  • 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