- Python 3
- Két python könyvtár telepítése
- pip3 install pandas
- pip3 install xlwt
Futtatás: python3 covid2xls.py
Kód:
import requests
import bs4
from bs4 import BeautifulSoup
import pandas as pd
#######################xlwt###########################
import xlwt
from xlwt import Workbook
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
sheet1.write(0, 0, 'Sorszám ')
sheet1.write(0, 1 ,'Nem')
sheet1.write(0, 2 ,'Kor')
sheet1.write(0, 3 ,'Alapbetegségek')
count=0
#######################xlwt###########################
for i in range(0,40):
user_agent = 'Chrome/80.0.3987.132 Mozilla/5.0'
response = requests.get(f"https://koronavirus.gov.hu/elhunytak?page={i}", stream=True,headers={'User-Agent': user_agent})
soup = BeautifulSoup(response.text, 'html.parser')
tables = soup.find_all('table')
df = pd.read_html(str(tables))[0]
print(df)
for i in range(0,len(df["Sorszám"])):
count=count+1
sheet1.write(count, 0, str(df["Sorszám"][i]))
sheet1.write(count, 1 ,str(df["Nem"][i]))
sheet1.write(count, 2 ,int( df["Kor"][i]))
sheet1.write(count, 3 ,str(df["Alapbetegségek"][i]))
wb.save("out.xls")
import bs4
from bs4 import BeautifulSoup
import pandas as pd
#######################xlwt###########################
import xlwt
from xlwt import Workbook
wb = Workbook()
sheet1 = wb.add_sheet('Sheet 1')
sheet1.write(0, 0, 'Sorszám ')
sheet1.write(0, 1 ,'Nem')
sheet1.write(0, 2 ,'Kor')
sheet1.write(0, 3 ,'Alapbetegségek')
count=0
#######################xlwt###########################
for i in range(0,40):
user_agent = 'Chrome/80.0.3987.132 Mozilla/5.0'
response = requests.get(f"https://koronavirus.gov.hu/elhunytak?page={i}", stream=True,headers={'User-Agent': user_agent})
soup = BeautifulSoup(response.text, 'html.parser')
tables = soup.find_all('table')
df = pd.read_html(str(tables))[0]
print(df)
for i in range(0,len(df["Sorszám"])):
count=count+1
sheet1.write(count, 0, str(df["Sorszám"][i]))
sheet1.write(count, 1 ,str(df["Nem"][i]))
sheet1.write(count, 2 ,int( df["Kor"][i]))
sheet1.write(count, 3 ,str(df["Alapbetegségek"][i]))
wb.save("out.xls")
Nincsenek megjegyzések:
Megjegyzés küldése