-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_restaurant_info.py
56 lines (43 loc) · 1.35 KB
/
get_restaurant_info.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
__author__ = "Akhil Gupta"
'''
This script is used to get the information about the hotel
such as Id, Name, url, Stars, Ratings.
'''
import urllib2
import re
from bs4 import BeautifulSoup as bs
class RestaurantInfo():
def __init__(self):
self.fobj = open('restaurant_info.txt', 'a')
def getInfo(self):
page = 1
while(page<=89):
dic = {}
url=urllib2.urlopen("http://www.burrp.com/bangalore/restaurants/"+str(page)).read()
soup=bs(url)
div=soup.find("div",{"class":"restnt_list_wrap"})
ul=div.find("ul",{"id":"listing_content"})
li=ul.findAll("li")
for ele in range(len(li)):
try :
a_tag = li[ele].find("a")
hotel_link = a_tag.get("href")
hotel_name =a_tag.getText()
temp = hotel_link.split('/')
hotel_id = temp[-1]
star = li[ele].find("div",{"class":"list_star"}).getText()
rating = li[ele].find("div",{"class":"list_rat"}).getText()
rating = re.findall(r'\d+',rating)[0]
dic["hotel_link"] = str(hotel_link)
dic["hotel_id"] = str(hotel_id)
dic["hotel_star"] = eval(star)
dic["hotel_rating"] = eval(rating)
dic["hotel_name"] = str(hotel_name)
self.fobj.write(str(dic) + '\n')
except Exception as e:
print "Exception ::", e
print "Finished page ==> ",page
page+= 1
if __name__ =="__main__":
obj = RestaurantInfo()
obj.getInfo()