Skip to content

Instantly share code, notes, and snippets.

@lakshay-arora
Last active September 30, 2019 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakshay-arora/127d4f270b162ab6aa37ec33d5ba235e to your computer and use it in GitHub Desktop.
Save lakshay-arora/127d4f270b162ab6aa37ec33d5ba235e to your computer and use it in GitHub Desktop.
# 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