Last active
September 30, 2019 06:27
-
-
Save lakshay-arora/127d4f270b162ab6aa37ec33d5ba235e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list to store the data | |
scraped_data = [] | |
for card in cards_data: | |
# initialize the dictionary | |
card_details = {} | |
# get the hotel name | |
hotel_name = card.find('p') | |
# get the room price | |
room_price = card.find('li', attrs={'class': 'htl-tile-discount-prc'}) | |
# add data to the dictionary | |
card_details['hotel_name'] = hotel_name.text | |
card_details['room_price'] = room_price.text | |
# append the scraped data to the list | |
scraped_data.append(card_details) | |
# create a data frame from the list of dictionaries | |
dataFrame = pd.DataFrame.from_dict(scraped_data) | |
# save the scraped data as CSV file | |
dataFrame.to_csv('hotels_data.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment