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!
-
2What you are describing goes against facebook's policy here: facebook.com/apps/site_scraping_tos_terms.phpJuan– Juan2018-06-18 21:28:47 +00:00Commented Jun 18, 2018 at 21:28
-
Nu uh, we ain't gonna help you with that, as the comment by @Juan points out it's against their policyDev Man– Dev Man2018-06-18 21:31:41 +00:00Commented Jun 18, 2018 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– Andrej Georgiev2018-06-18 21:33:49 +00:00Commented Jun 18, 2018 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– RoboBear2018-06-18 21:34:40 +00:00Commented Jun 18, 2018 at 21:34
-
Oh, feel like a criminal right now, quess il stop, thanks so much!Andrej Georgiev– Andrej Georgiev2018-06-18 21:35:53 +00:00Commented Jun 18, 2018 at 21:35
2 Answers
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/
1 Comment
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: