I'm trying to get the table at this URL: https://www.agenas.gov.it/covid19/web/index.php?r=site%2Ftab2 . I tried reading it qith requests and BeautifulSoup:
from bs4 import BeautifulSoup as bs import requests s = requests.session() req = s.get('https://www.agenas.gov.it/covid19/web/index.php?r=site%2Ftab2', headers={ "User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) " "Chrome/51.0.2704.103 Safari/537.36"}) soup = bs(req.content) table = soup.find('table') However, I only get the headers of the table.
<table class="table"> <caption class="pl8">Ricoverati e posti letto in area non critica e terapia intensiva.</caption> <thead> <tr> <th class="cella-tabella-sm align-middle text-center" scope="col">Regioni</th> <th class="cella-tabella-sm bg-blu align-middle text-center" scope="col">Ricoverati in Area Non Critica</th> <th class="cella-tabella-sm bg-blu align-middle text-center" scope="col">PL in Area Non Critica</th> <th class="cella-tabella-sm bg-blu align-middle text-center" scope="col">Ricoverati in Terapia intensiva</th> <th class="cella-tabella-sm bg-blu align-middle text-center" scope="col">PL in Terapia Intensiva</th> <th class="cella-tabella-sm bg-blu align-middle text-center" scope="col">PL Terapia Intensiva attivabili</th> </tr> </thead> <tbody id="tab2_body"> </tbody> </table> So I tried with the URL i think the table is located: https://Agenas:[email protected]/covid19/web/index.php?r=json%2Ftab2 . But in this case I always get 401 status code, even adding in headers username and password as shown in previous request. For example:
requests.get('https://Agenas:[email protected]/covid19/web/index.php?r=json%2Ftab2', headers={'username':'Agenas', 'password':'tab2-19' 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'}) Any idea on how to solve this? Thank you.
selenium.