-
Hi, I am a green hand here, and thanks a million for the daftlistings codes: for listing in listings: I attempted to list these items into a pandas dataframe layout and export the results into an excel format, somehow I failed to do so, Can anyone helps me on this matter? Thanks again. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you want something openable with excel, then use the import csv
from daftlistings import Daft, Location, SearchType, PropertyType
daft = Daft()
daft.set_location(Location.DUBLIN)
daft.set_search_type(SearchType.RESIDENTIAL_RENT)
daft.set_property_type(PropertyType.APARTMENT)
daft.set_max_price(700)
listings = daft.search()
with open('./listings.csv', 'w', newline='', encoding='utf-8') as F:
writer = csv.writer(F)
writer.writerow(['title', 'price', 'link']) # Column names
for listing in listings:
writer.writerow([listing.title, listing.price, listing.daft_link]) If you really want the listings in a import pandas as pd
from daftlistings import Daft, Location, SearchType, PropertyType
daft = Daft()
daft.set_location(Location.DUBLIN)
daft.set_search_type(SearchType.RESIDENTIAL_RENT)
daft.set_property_type(PropertyType.APARTMENT)
daft.set_max_price(700)
listings = daft.search()
# Convert to a list of dictionaries
listings = [
{'title': listing.title,
'price': listing.price,
'link': listing.daft_link} for listing in listings
]
df = pd.DataFrame.from_dict(listings)
print(df) |
Beta Was this translation helpful? Give feedback.
If you want something openable with excel, then use the
csv
package from the standard library. Make sure to open withencoding='utf-8'
or the euro symbol will get mangled.