-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcardapiogetter.py
47 lines (36 loc) · 1012 Bytes
/
cardapiogetter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from bs4 import BeautifulSoup as soup
from urllib.request import urlopen
import pandas as pd
def getCardapio(url):
data = []
html = urlopen(url)
res = soup(html.read(), "html.parser")
tbody = res.find('tbody')
tableRows = tbody.find_all('tr')
tableRows.pop(0)
for row in tableRows:
columns = row.find_all('td')
if row:
output_row = []
for column in columns:
output_row.append(column.text)
data.append(output_row)
df = pd.DataFrame(data)
dfLunch = df.iloc[0:8]
dfLunch.reset_index(drop=True)
dfDinner = df.iloc[8:16]
new_header = dfLunch.iloc[0]
new_header[4] = "Quinta-Feira"
dfLunch = dfLunch[1:]
dfLunch.columns = new_header
new_header = dfDinner.iloc[0]
new_header[4] = "Quinta-Feira"
dfDinner = dfDinner[1:]
dfDinner.columns = new_header
if (dfLunch is not None) and (dfDinner is not None):
print("Resultado pronto!")
print(url)
print(dfLunch, dfDinner)
return [dfLunch, dfDinner]
else:
print("Erro")