kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.35k stars 626 forks source link

dict contains fields not in fieldnames: 'images' #192

Closed wgicio closed 3 years ago

wgicio commented 3 years ago

macca@macca:~/Documents$ facebook-scraper --filename 1523008504577896.csv --pages 15 1523008504577896 Traceback (most recent call last): File "/usr/local/bin/facebook-scraper", line 8, in sys.exit(run()) File "/home/macca/.local/lib/python3.8/site-packages/facebook_scraper/main.py", line 45, in run write_posts_to_csv( File "/home/macca/.local/lib/python3.8/site-packages/facebook_scraper/init.py", line 165, in write_posts_to_csv dict_writer.writerows(list_of_posts) File "/usr/lib/python3.8/csv.py", line 157, in writerows return self.writer.writerows(map(self._dict_to_list, rowdicts)) File "/usr/lib/python3.8/csv.py", line 149, in _dict_to_list raise ValueError("dict contains fields not in fieldnames: " ValueError: dict contains fields not in fieldnames: 'images'

neon-ninja commented 3 years ago

What version are you using?

wgicio commented 3 years ago

facebook-scraper 0.2.26

neon-ninja commented 3 years ago

Does the script still generate a CSV despite the error? If so, can you post its contents here?

kevinzg commented 3 years ago

The CSV writer function uses the first post to get the columns to use as headers, and images is not always set. Adding images to the make new post function should fix this problem.

neon-ninja commented 3 years ago

I see - here's a PR for that https://github.com/kevinzg/facebook-scraper/pull/193/files