Closed Ginny47 closed 4 years ago
hi @Ginny47, here's a minimal example that works for me:
import csv
import craigslist
from craigslist._search.jsonsearch import JSONSearchPost
with open('craigslist_sfbayarea.txt', 'w') as f:
writer = csv.DictWriter(f, fieldnames=JSONSearchPost._fields)
for post in craigslist.search('sfbay', 'apa', postal=95033, search_distance=1):
print(post)
writer.writerow(post._asdict())
I think in particular you were looking for the post._asdict()
method.
Could anyone help with printing JSONSearchPost in txt or csv file format?