shaikhsajid1111 / facebook_page_scraper

Scrapes facebook's pages front end with no limitations & provides a feature to turn data into structured JSON or CSV
https://pypi.org/project/facebook-page-scraper/
MIT License
220 stars 67 forks source link

delete first json's element #67

Open ihabpalamino opened 1 year ago

ihabpalamino commented 1 year ago

the result i get after scraping is this; [{"1766004853797710": {"username": "2M.ma", "shares": 0, "likecount": 101, "replycount": 0, i want to remove the status wich is in this case 1766004853797710 and put it in this way "id_post":1766004853797710 next to username likecount..

KBrianNgeno commented 1 year ago

Try this:

`#call the scrap_to_json() method scraper_json = meta_ai.scrap_to_json()

converts returned json to python dict

json_data = json.loads(scraper_json)

fetch all keys(post ids)

post_ids = json_data.keys()

posts = []

loop through all posts fetching only the fields you want

for id in post_ids: post = json_data[id] post_json = {'id' : id ,'username' : post : post['username'], 'likecount' : post['likecount']} posts.append(post_json)

print(posts)`