-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmt_yatra_data.py
148 lines (114 loc) · 4.07 KB
/
mmt_yatra_data.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import re
from selenium import webdriver
driver = webdriver.Chrome('C:/chromedriver.exe')
driver.get('https://flights.makemytrip.com/makemytrip/search/O/O/E/1/0/0/S/V0/DEL_BOM_05-03-2018?contains=false&remove=')
html_page_mmt = driver.page_source
driver.get('https://flight.yatra.com/air-search-ui/dom2/trigger?ADT=1&CHD=0&INF=0&class=Economy&destination=BOM&destinationCountry=IN&flexi=0&flight_depart_date=05/03/2018&noOfSegments=1&origin=DEL&originCountry=IN&source=fresco-home&type=O&version=1.15&viewName=normal')
from urllib.request import urlopen
from bs4 import BeautifulSoup
import ssl
# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
#serviceurl='https://www.makemytrip.com/'
#url='https://flights.makemytrip.com/makemytrip/search/O/O/E/1/0/0/S/V0/DEL_BOM_06-03-2018?contains=false&remove='
html_page_yatra = driver.page_source
#********************************************************************************
driver.get('https://flights.makemytrip.com/makemytrip/search/O/O/E/1/0/0/S/V0/DEL_BOM_05-03-2018?contains=false&remove=')
html_page_mmt = driver.page_source
driver.quit()
#********************************************************************************
soup=BeautifulSoup(html_page_yatra,"html.parser")
tags=soup('span')
#a=soup.find_all("span",{"class":"block city_name hidden-xs visible-stb ng-binding"})
airlin=soup.find_all("small",{"class":"fs-sm gray fl ml5 name carrier-name"})
dept_tim=soup.find_all("span",{"class":"time-color","ng-bind":"flt.dd"})
arr_tim=soup.find_all("span",{"class":"time-color","ng-bind":"flt.ad"})
flt_n=soup.find_all("small",{"class":"fs-10 ltr-gray fl ml5 nowrap"})
price=soup.find_all("del",{"class":"fs-sm lt-gray block ng-hide"})
journey=soup.find_all("small",{"class":"fs-10 ltr-gray block stop-tooltip three-dot"})
tempo=list()
finalpric=list()
airline=list()
dept_time=list()
arr_time=list()
flt_no=list()
finalprice=list()
journey_type=list()
#handle=open('random.txt','w')
for i in airlin:
#handle.write("%s\n" % i.contents)
tempo.append(i.contents)
for i in tempo:
airline.append(i[0])
del tempo[:]
for i in dept_tim:
#handle.write("%s\n" % i.contents)
tempo.append(i.contents)
for i in tempo:
dept_time.append(i[0])
del tempo[:]
#handle.write("******\n")
for i in arr_tim:
#handle.write("%s\n" % i.contents)
tempo.append(i.contents)
for i in tempo:
arr_time.append(i[0])
del tempo[:]
#handle.write("******\n")
for i in flt_n:
#handle.write("%s\n" % i.contents)
tempo.append(i.contents)
for i in tempo:
flt_no.append(i[0])
del tempo[:]
for i in price:
t=str(i)
temp=re.findall(r'[0-9][0-9,]+',t)
finalpric.append(temp)
finalpric = [v for i, v in enumerate(finalpric) if i % 2 == 0]
for i in finalpric:
#handle.write("%s\n" % i)
tempo.append(i)
for i in tempo:
finalprice.append(i[0])
for i in journey:
#handle.write("%s\n" % i)
tempo.append(i.contents)
for i in tempo:
journey_type.append(i[0].rstrip())
print(airline)
print(dept_time)
print(arr_time)
print(flt_no)
print(finalprice)
print(journey_type)
#**************************************************************************************
print("######################")
soup=BeautifulSoup(html_page_mmt,"html.parser")
#tags=soup('span')
#a=soup.find_all("span",{"class":"block city_name hidden-xs visible-stb ng-binding"})
#b=soup.find_all("span",{"class":"block timeCa RobotoRegular ng-binding"})
f_no=soup.find_all("span",{"class":"block logo_name hidden-xs visible-stb light_gray flt_number_less600 ng-binding ng-scope"})
cost=soup.find_all("span",{"class":"num ng-binding"})
tempor=list()
mmt_f_n=list()
mmt_cost=list()
for i in f_no:
#print(i.contents)
#handle.write("%s\n" % i.contents)
tempor.append(i.contents)
for i in tempor:
mmt_f_n.append(i[0])
del tempor[:]
for i in cost:
#print(i.contents)
#handle.write("%s\n" % i.contents)
tempor.append(i.contents)
for i in tempor:
mmt_cost.append(i[0])
del tempor[:]
print(mmt_f_n)
print(mmt_cost)
#handle.close()