I am scraping some data with Python and after getting data into Python I am unable to add it to dataframe. I am not getting any errors but my dataframe keeeps returning empty after execution. Here is my code:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = 'https://www.airbnb.com/s/Honolulu--HI--United-States/homes?tab_id=home_tab&refinement_paths%5B%5D=%2Fhomes&flexible_trip_lengths%5B%5D=one_week&price_filter_input_type=0&query=Honolulu%2C%20HI&place_id=ChIJTUbDjDsYAHwRbJen81_1KEs&date_picker_type=calendar&checkin=2022-10-08&checkout=2022-10-09&source=structured_search_input_header&search_type=autocomplete_click'
page = requests.get (url, headers = {'User-agent': 'your bot 0.1'})
soup = BeautifulSoup(page.text, 'lxml')
df = pd.DataFrame({'Links': [''], 'Title': [''], 'Price' : [''], 'Rating': ['']})
postings = soup.findAll('div', class_= 'c4mnd7m dir dir-ltr')
for post in postings:
try:
title = post.find('div', class_ = 't1jojoys dir dir-ltr').text
link = 'https://www.airbnb.com/' + post.find('a', class_ = 'ln2bl2p dir dir-ltr').get('href')
price = post.find('span', class_ = 'a8jt5op dir dir-ltr').text
rating = post.find('span', class_ = 'ru0q88m dir dir-ltr').text
df.concat({'Links': link, 'Title': title, 'Price' : price, 'Rating': rating }, ignore_index = True)
except:
pass
print(df)
I can see values for title, link, price, rating variables so I believe the issues lies with this line of code:
df.concat({'Links': link, 'Title': title, 'Price' : price, 'Rating': rating }, ignore_index = True)
except:
pass
Tried with df.append with no luck. Any help very much appreciated.