0

I'm looking to get some data from a Facebook page of a restaurant, but I'm kinda stuck. I want to load some divs from the facebook page of the restaurant, then get the ID's of the divs, since they contain some information i would like to use. Ive tried using the .load function from jQuery, but no luck. Of all the answers I've seen, they all include a url that's something like somefile.html. Is it possible to load the divs ids and some innerHTML from a live page like Facebook? Are they somehow downloading the html to a file then using that? Keep in mind I know nothing about PHP, so any solutions? Thanks!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    What you are describing goes against facebook's policy here: https://www.facebook.com/apps/site_scraping_tos_terms.php – Juan Jun 18 '18 at 21:28
  • Nu uh, we ain't gonna help you with that, as the comment by @Juan points out it's against their policy – Dev Man Jun 18 '18 at 21:31
  • I cant collect simple things like div id's even though everyone can just inspect element and see the id, also im looking to collect the div id's of only 2-3 restaurants, is that still a problem ? – Andrej Georgiev Jun 18 '18 at 21:33
  • @AndrejGeorgiev What the other users are saying is Facebook's Usage Policy essentially forbids "web scraping" Facebook pages, which is what you're trying to do. – RoboBear Jun 18 '18 at 21:34
  • Oh, feel like a criminal right now, quess il stop, thanks so much! – Andrej Georgiev Jun 18 '18 at 21:35
  • @AndrejGeorgiev when you click inspect element, it is you, a person. No different to visiting the site. When it comes to a script or similar, it goes against item # 2 in facebook's policy: 2. You will not engage in Automated Data Collection without Facebook's express written permission. – Juan Jun 18 '18 at 21:36
  • Just use the graph API for getting your data as one of the answers points out. That is the correct and legal way to do it – Dev Man Jun 18 '18 at 21:44

2 Answers2

2

The right way to do it would be though Facebooks graph API, take a look at this site and see if it offers the information you need https://developers.facebook.com/docs/graph-api/reference/page/

Benjaco
  • 303
  • 3
  • 11
0

NOTE

As comments have pointed out, "web scraping" is FORBIDDEN on Facebook.com by Facebook policy. http://www.facebook.com/apps/site_scraping_tos_terms.php


Technically, I don't think this is possible with Facebook and just JavaScript.

In general, using just JavaScript, one solution would be to load the (external) site like FaceBook into an Iframe, and then grab all the DIVs and search the DOM that's loaded into the iFrame. However, I believe FaceBook (and other sites) set something called "CORS Request Headers" which prevent the page from loading into an iFrame -- also, as far as I know, this cannot be hacked around except to use another language to pull the HTML as a file (like with PHP).

Sources:

  1. Facebook Forbids iFrames
  2. JavaScript, Load Page in iFrame
RoboBear
  • 5,434
  • 2
  • 33
  • 40