#!/usr/bin/python3 # -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup urlAnd = 'https://www.govern.ad/covid/taula.php' headers = {'User-Agent':'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0'} resp = requests.get(urlAnd, headers=headers) webAnd = BeautifulSoup(resp.text, "lxml") webAnd = webAnd.get_text() webAnd = webAnd.split('\n') webAnd = [line for line in webAnd if line.strip() != ""] outfile = open("and.txt", "w") i=0 tmp='' for txt in webAnd: if i == 0: outfile.write(txt+'\n') outfile.write('\n') elif i==11: outfile.write('\n-------\n') outfile.write(txt+'\n') outfile.write('\n') elif i%2==1: tmp=txt+': ' elif i%2==0: tmp=tmp+txt+'\n' outfile.write(tmp) tmp='' i+=1 outfile.close()