facebook-scraper icon indicating copy to clipboard operation
facebook-scraper copied to clipboard

Page review throws error when there is review but there is no text

Open suarezjessie opened this issue 2 years ago • 1 comments

I tried looking into the profile reviews and I found out that the code throws an error whenever there is a review but there is no text. Example code and page is shown below

profile = get_page_info('IndulgeGoldJewelryShopPH')
for review in profile['reviews']:
    print(review)

Here's the output

{'user_url': 'https://facebook.com/charrie.cruzii', 'username': 'Charrie Mae Aquino Cruz', 'profile_picture': 'https://scontent.fmnl9-1.fna.fbcdn.net/v/t39.30808-1/271598507_637511384161110_1537246800197351725_n.jpg?stp=cp0_dst-jpg_e15_p40x40_q65&_nc_cat=108&ccb=1-5&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_eui2=AeHedFkUlADa4pXp_YYEkYG0V8045WcVkbxXzTjlZxWRvE9iKeUKts3zr2oMDdq38P7QgqC05YeneVY7IMVDzCOp&_nc_ohc=_FrJ4ru3k_AAX9_9l_M&_nc_ht=scontent.fmnl9-1.fna&oh=00_AT92GhM6rBWD0hzTpWUa4k0EvJrwjWw-d4vi7rqFderXhg&oe=622207C0', 'text': '101% LEGIT ♥️ Ganda ng Japan gold ko khit nkktakot bumili sa online hindi ako binigo ni Ma’am sa items ko.', 'time': datetime.datetime(2021, 6, 15, 0, 22, 2), 'timestamp': 1623687722, 'recommends': True, 'post_url': 'https://facebook.com/story.php?story_fbid=508729293705987&id=100037067623937'}
{'user_url': 'https://facebook.com/lhourieann.sales', 'username': 'Lhourie Ann Pelante Sales', 'profile_picture': 'https://scontent.fmnl9-3.fna.fbcdn.net/v/t39.30808-1/271669536_4940354555987661_1372735280350021459_n.jpg?stp=cp0_dst-jpg_e15_p40x40_q65&_nc_cat=100&ccb=1-5&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_eui2=AeFER6cKluDwXoN7Tsg2VELco4LB8_XSLYejgsHz9dIthxnN7NtxQwE4Xu-188B2NOvKybf8sLgDEWqp4r84p_-O&_nc_ohc=xUFbzLpvUr4AX-JQWdv&_nc_ht=scontent.fmnl9-3.fna&oh=00_AT-LgKHTr71oRc0g2f1JjPjqz3snQWkg-SY2QGxr5Ju08w&oe=622354CF', 'text': "legit na legit❤ thankyou ma'am sa uulitin❤", 'time': datetime.datetime(2021, 8, 13, 12, 27, 40), 'timestamp': 1628828860, 'recommends': True, 'post_url': 'https://facebook.com/story.php?story_fbid=4437857939570661&id=100000394951364'}
{'user_url': 'https://facebook.com/aldrincarlo.ligoro', 'username': 'Aldrin Carlo Ligoro', 'profile_picture': 'https://scontent.fmnl9-3.fna.fbcdn.net/v/t1.6435-1/83539326_3358384224177012_8198766747549958144_n.jpg?stp=cp0_dst-jpg_e15_p40x40_q65&_nc_cat=104&ccb=1-5&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_eui2=AeGZKYKTMMmgDApY4cEc3bJhcVcY1soyWxZxVxjWyjJbFrQIGw4bHR3kQwICPHCJu4Nh2mA67kRBCTcGMvSjvji1&_nc_ohc=zQUuOHYGr5QAX_9VedC&_nc_ht=scontent.fmnl9-3.fna&oh=00_AT8FgeWKCb1YVS02jWDGjuScqj3sI3_x_im-mR89N1ofTQ&oe=6242CB50', 'text': 'legit seller! ambait pa ni ms maria!\ntysm po sa smooth transaction..\nms rose tysm din po!\ntill my next txn.. :)', 'time': datetime.datetime(2022, 1, 22, 15, 3, 5), 'timestamp': 1642834985, 'recommends': True, 'post_url': 'https://facebook.com/story.php?story_fbid=5549651621716917&id=100000164018412'}
{'user_url': 'https://facebook.com/loryne.shoppe', 'username': 'Lor Ryn', 'profile_picture': 'https://scontent.fmnl9-2.fna.fbcdn.net/v/t39.30808-1/226066919_954581695385625_23247053200523701_n.jpg?stp=cp0_dst-jpg_e15_p40x40_q65&_nc_cat=103&ccb=1-5&_nc_sid=dbb9e7&efg=eyJpIjoidCJ9&_nc_eui2=AeFcAbOfOVMJNWZs6xTO2VZeSZX3Q_yG5gpJlfdD_IbmCsjZ5S-wqxF-o7szsEAGjbk-vFYpYPl_b_YONNsT3WtN&_nc_ohc=kW_FAK8xrkoAX9OqaX-&_nc_ht=scontent.fmnl9-2.fna&oh=00_AT8z49pfSzI_5JXkFB5srFnuQ2eG8fQ1Y6KgNG3c0h8i1g&oe=6221927E', 'text': 'mabait na mabait ang may ari nito at super liget 101%liget', 'time': datetime.datetime(2018, 4, 12, 20, 41, 6), 'timestamp': 1523536866, 'recommends': True, 'post_url': 'https://facebook.com/story.php?story_fbid=226536608190141&id=100025014096717'}
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/25/k79djfcj737dwxvhtkr192zr8p8x5p/T/ipykernel_79246/3556657984.py in <module>
----> 1 for review in profile['reviews']:
      2     try:
      3         print(review)
      4     except:
      5         continue

~/opt/anaconda3/envs/verified_seller_program/lib/python3.8/site-packages/facebook_scraper/facebook_scraper.py in get_page_reviews(self, page, **kwargs)
    557                     "username": links[0].text,
    558                     "profile_picture": elem.find("img", first=True).attrs["src"],
--> 559                     "text": text_elem.find("span p", first=True).text,
    560                     "time": datetime.fromtimestamp(time),
    561                     "timestamp": time,

AttributeError: 'NoneType' object has no attribute 'text'

When I look at the page and its reviews, I can see that some reviews only rated the page and didn't put text in it which is shown in the screenshot below Screen Shot 2022-03-01 at 11 39 15 AM

suarezjessie avatar Mar 01 '22 03:03 suarezjessie

https://github.com/kevinzg/facebook-scraper/commit/57767342762c8eeeae3d661f19183ab91214d64d should fix this

neon-ninja avatar Mar 29 '22 22:03 neon-ninja