-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathturitopwebscrapping.py
59 lines (47 loc) · 1.59 KB
/
turitopwebscrapping.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
48
49
50
51
52
53
54
55
56
57
58
59
import requests
import sys
import logging
from bs4 import BeautifulSoup
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def webscrap(html):
dias = 0
maxdias = 5
soup = BeautifulSoup(html,'html.parser')
tabla = soup.table
events = soup.find_all('tr',class_='bookings-calendar-event')
textcalendar = ''
for event in events:
esFecha = event.find('div',class_='bookings-history-date-event')
esStatus = event.find('div',class_='offline-bookings-event-status')
cleanstatus= esStatus.getText().strip('\n')
status=cleanstatus.strip(' ')
esHour=event.find('div',class_='offline-bookings-event-time-inner')
hora=esHour.getText().strip('\n')
esPeople=event.find('div',class_='offline-bookings-event-total-booked-seats opacity-lomed')
esStatus.getText()
if esPeople != None:
people = esPeople.getText().strip('\n')
else:
people = ''
if esFecha != None:
dias +=1
if dias == maxdias:
break
date = esFecha.getText()
textcalendar = textcalendar + '\n' + date + '\n'
else:
date = ''
if 'Deshacer' in status:
status = 'Bloqueado'
peope = ''
textcalendar = textcalendar + hora + ' ' + status + ' ' + people + '\n'
return textcalendar
def weblogin(urlLogin,loginData,urlData):
session = requests.session()
r = session.post(urlLogin, data=loginData)
cal=session.get(urlData)
calendar=cal.text
resultados = webscrap(calendar)
r.close
return resultados