-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyatra.py
106 lines (80 loc) · 2.64 KB
/
yatra.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
import re
from selenium import webdriver
driver = webdriver.Chrome('C:/chromedriver.exe')
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=26/02/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 = driver.page_source
driver.quit()
soup=BeautifulSoup(html_page,"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)