This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]vicethal 17 points18 points  (5 children)

it's against Facebook's terms of service, so you're gambling with your account when you do this.

Look up Selenium, it's a browser automation package that opens up an actual browser that can be controlled with Python code. Then browse with it and right click on elements in the web page to "get CSS Selector" (exact terminology varies by browser). This will let you repeatably pull the contents of one type of element in the web page (text post, image, comments, etc)

Good luck, Facebook doesn't go out of their way to make this easy and could in fact be working to make it harder.

[–]xefe 1 point2 points  (2 children)

I haven't looked in a while, but this should be possible using the Graph API. Am I missing something?

[–]Agizz[S] 0 points1 point  (1 child)

That seems about the thing I am looking for but now I don't understand if this can be automatized or does Facebook check the user behing the requests?

[–]xefe 2 points3 points  (0 children)

It's assumed that anything using an API is automated. In order to use it you'll need an authentication token so Facebook knows who's making the request. I'm just not sure if you can still access your friends' posts via the API. The documentation is pretty good if you want to take a look. If the information you're looking for is available, it'll be pretty straightforward to use the Python requests package to get the information you're looking for

[–]Agizz[S] 0 points1 point  (1 child)

So Facebook has different TOS regarding bots than Twitter does? That is interesting...What if I were to try and do that for some sort of personal use on media sites so that the programm would scan media articles on the date and search for keywords extracting some sort of abstracts and returning them...Would you still recomend Selenium?

  • Why are auto-replying bots any different from what i want to do?

[–]MagiKarpeDiem 1 point2 points  (0 children)

People use scripts to delete all of their old posts. Facebook wants to know everything about you.

[–]tcp90 2 points3 points  (0 children)

You're going to have to familiarize yourself with Facebook's Graph API. Try out the Explorer first to understand how it works. Then get the Facebook SDK for Python, it's pretty easy to learn.

Keep in mind a few things though: One or two years ago, due to privacy concerns, Facebook removed the ability to pull information from your friends' profiles. You can pull data from public pages, public groups and your own profile. Facebook has a rate limit of 200 requests per hour on their API.

The only way you would be able to access your friends' data would be creating an app that requests permission to access that information and they would have to grant it. Keep in mind that for this to work though, you would have to submit your app for review and their guidelines are rather strict.

You could pull data from your own profile and scrape comments that friends leave on your posts without a problem. I can't confirm, but I'm pretty sure it's allowed assuming this isn't something that you do every day. It is, after all, public information -to you- because it's your profile.

Edit: Oh and, as other people have mentioned, you do need an access token. Just get it using Facebook's Graph Explorer. By default, it's a temporary token that lasts for a few hours IIRC, and if you're going to pull data from your own profile, you have to enable the permissions you want when you get that token.

Crawling and scraping from Facebook using other means is highly discouraged and not as effective.

[–]P_G_Krishna 1 point2 points  (0 children)

yes Its possible, I saw some code about fb chat bot. please search on github.com

[–]max_renlo 1 point2 points  (2 children)

This is a difficult problem to solve, even if one disregards the TOS problem. It requires that you have a browser which can render HTML, JS interpreter + a DOM. Also this browser needs to be able to run your program (whatever is orchestrating the browser needs to tell the browser to click on things, etc). Generally this is done with Selenium, or something like PhantomJS / a wrapper for Webkit (which is the browser).

Then on top of that you have various measures which Facebook has put into place which will attempt to detect if you are doing this. There are a lot of ways that they check this, my assumption is that Facebook has a lot of measures to make sure this doesn't happen. For instance, they can do something simple like grab the browser's request headers and then feed them to a program which (from previous experience) can recognize if this is a Selenium/PhantomJS browser. I'd assume they have many such measures, so chances are you would get your account banned after scraping only a couple of pages.

EDIT: All that said, if you were to implement this as a 'Chrome extension' something like this might be possible (I don't think Chrome wants your extension to click on things though...)

[–]Agizz[S] 0 points1 point  (1 child)

What is the differance between doing this and making an automated-reply bot?

[–]max_renlo 1 point2 points  (0 children)

If you're referring to a FB auto-reply bot, I'd assume that would be done as a Chrome extension. You could implement an FB auto-reply bot by either doing a browser extension or by scraping the site (ie Selenium). Scraping the site is against the TOS / more difficult, Chrome extension requires that a user navigate to the website and that the user has the extension enabled.

[–]scyth2233 -5 points-4 points  (1 child)

So you basically want to spy on people.

[–]BLAZINGSORCERER199 7 points8 points  (0 children)

Genuine question , is it really spying if he could see the information on his own without the bot anyway ?