kevinzg / facebook-scraper

Scrape Facebook public pages without an API key
MIT License
2.45k stars 633 forks source link

Get likes' category with get_profile() #669

Closed TheGennesis closed 2 years ago

TheGennesis commented 2 years ago

Hi! This is not an issue, it's a question.

I read that passing the parameter likes=True in the function get_profile(), you can retrieve all pages that a certain user like. However, the "like" object contains only the page name and the page link.

Is there a way to get the like's category and the like's id too? For example, for film "TitanicMovie", I would get: { "name": "Titanic", "link": "/TitanicMovie", "likeID": 5723846957 (dummy id), "category": "Film and TV series" }

neon-ninja commented 2 years ago

The scraper does return likes_by_category, it looks like this (from https://github.com/kevinzg/facebook-scraper/issues/586):

 'likes_by_category': {'All Likes': 1507,
                       'Artists': 180,
                       'Athletes': 1,
                       'Movies': 5,
                       'Restaurants': 7,
                       'Sports Teams': 4,
                       'TV Shows': 28},

If that doesn't suffice, I guess you could loop through all the likes and call get_page_info(like["link"]), but that would probably take a long time. Here's an example:

pprint(get_page_info("TitanicMovie"))

outputs:

{'about': 'About\n'
          'http://www.TitanicMovie.com/\n'
          'Movie\n'
          '@titanic.movie\n'
          'LOS ANGELES, CA (May 31, 2012) – The two billion-dollar box office '
          'phenomenon and winner of 11 Academy Awards®, TITANIC, makes its '
          'highly anticipated debut on Blu-ray 2D and 3D on September 10, 2012 '
          'from Twentieth Century Fox Home Entertainment and Paramount Home '
          'Media Distribution. Available in high definition for the first time '
          'ever, James Cameron’s timeless and unforgettable tour de force will '
          'be presented in stunning 2D and 3D, providing a cinematic in-home '
          'experience of TITANIC like never before. Marking 101 years ago '
          'today that the RMS Titanic was launched into the Belfast Lough, '
          'film fans worldwide can now pre-order the epic love story on '
          'Blu-ray 2D or Blu-ray 3D with participating online retailers.\n'
          '\n'
          'Commented James Cameron, “Blu-ray extends TITANIC’s immersive 3D '
          'theatrical experience into audiences’ homes, where their living '
          'room becomes the backdrop for big spectacular environments and '
          'intense action, as well as profoundly intimate human moments, '
          'allowing generations of fans – new and old – to truly become part '
          'of the movie like never before.”\n'
          '\n'
          'This ultimate high-definition presentation of TITANIC is a must '
          'have for film fans’ home media collections. The Blu-ray features '
          'more than 2 ½ hours of all-new bonus footage including a '
          'fascinating in-depth exploration of the film with James Cameron, as '
          'well as documentary footage produced by National Geographic with '
          "James Cameron that brings the world's leading RMS Titanic experts "
          'together to solve the lingering mysteries of why and how the '
          '“unsinkable" ship sank. The Blu-ray also boasts previously released '
          'special features including 29 deleted scenes, an alternate ending, '
          'over 60 behind-the-scenes featurettes, a look at the groundbreaking '
          'visual effects, over 2,000 photos, three commentaries and much, '
          'much more.\n'
          '\n'
          'Starring Leonardo DiCaprio and Kate Winslet in the roles that would '
          'make them global stars, TITANIC tells the story of the epic romance '
          'between two star-crossed lovers against the backdrop of the '
          'legendary and ill-fated maiden voyage of the “ship of dreams.”\n'
          'See all',
 'address': None,
 'cover_photo': 'https://scontent.fakl8-1.fna.fbcdn.net/v/t1.6435-9/fr/cp0/e15/q65/117357203_3544561898896579_7992014078248731844_n.jpg?_nc_cat=101&ccb=1-5&_nc_sid=ed5ff1&efg=eyJpIjoidCJ9&_nc_ohc=cSoR8lKUHigAX_NdT3s&_nc_ht=scontent.fakl8-1.fna&oh=00_AT92OVivUjoiuhbZH-72ddNyAr5LvpqEil4mgXdwbNo9Pg&oe=622F07BD',
 'followers': 50009275,
 'foundingDate': '2011-05-19T12:10:30-0700',
 'identifier': 216410885045047,
 'image': None,
 'likes': 51118720,
 'name': 'Titanic',
 'profile_photo': 'https://scontent.fakl8-1.fna.fbcdn.net/v/t1.18169-9/cp0/e15/q65/p64x64/431055_379075532111914_1704983527_n.jpg?_nc_cat=1&ccb=1-5&_nc_sid=85a577&efg=eyJpIjoidCJ9&_nc_ohc=jaHj4RO5mfgAX-AjfPo&_nc_oc=AQku1IBBzgxH1O_E8EWnVfbsZLUlnso3I1CrGy24gJlRZTboVPGdcrJup3K2BIzYWYc&_nc_ht=scontent.fakl8-1.fna&oh=00_AT_cBISUVhxlYSJCaG69wdRWcn3iDwB8bbYAuhipdFdUmA&oe=622C77AB',
 'rating': 'Movie',
 'reviews': <generator object FacebookScraper.get_page_reviews at 0x7f1c74c68900>,
 'sameAs': 'http://www.TitanicMovie.com',
 'type': 'Organization',
 'url': 'https://www.facebook.com/TitanicMovie/'}

The scraper can only extract things that are present in the HTML, and I don't see like IDs or categories on the all likes page (https://m.facebook.com/timeline/app_collection/?collection_token=620017078%3A2409997254%3A96)

TheGennesis commented 2 years ago

Ok, got it. Thank you!