I need to clear data from facebook game - using ruby

Revised (clarified question)

I spent several days trying to figure out how to clear certain information from playing facebook; however, I ran into a brick wall after a brick wall. As far as I can tell, the main problem is the following. I can use the Chrome validation tool to manually find the html I need - it appears inside the iframe. However, when I try to clear this iframe, it is empty (except for properties):

<iframe id="game_frame" name="game_frame" src="" scrolling="no" ...></iframe> 

This is the same result that I see if I use browsers' Page Viewer. I do not understand why I do not see the data in the iframe. The answer is NOT that it is added subsequently by AJAX. (I know that both due to the fact that "View page source" can read data that was added by Ajax, and also because I b / c I waited until I saw the data page before clearing it, and it still does not exist).

Is this due to scripting on the facebook screen, and if so? Or I just missed something. I program in ruby, and I tried nokogiri, then mechanized, then capybara without success.

I don’t know if any value matters, but it seems to me that the iframe gets the data using the iframe link "game_frame", which apparently refers to this part of the html that appears earlier in the document:

 <form id="hidden_login_form_1331840407" action="" method="POST" target="game_frame"> <input type="hidden" name="signed_request" autocomplete="off" value="v6kIAsKTZa..."> ... </form> 

Original question

I wrote a ruby ​​program that uses nokogiri to clear data from an HTML game on facebook. I am currently receiving HTML using the "check element" chrome element, and I save it in a file and parse it from there. However, I would really like to have access to information from the ruby. For example, I would give the program the page name "www.gamename.com/...?id=12345" and it will start on facebook, go to this page and clear the data. Currently, if I try to do this, this does not work, because I am redirected to the facebook login page. How can I go past the login screen to access the pages I need?

I would like to do this using the nokogiri code I already wrote; however, if I have to rewrite it using something else. Currently, the program is a separate program, not a rails program, but I can change that. I see some information that could point me towards Omniauth, but I'm not sure that what I'm looking for, and that also looks very complicated. I hope there will be a simpler solution.

thanks

+6
source share
2 answers

I can recommend capybara-webkit for this kind of task. It uses QtWebkit under the hood and understands Javascript:

 require 'capybara-webkit' require 'capybara/dsl' require 'nokogiri' include Capybara::DSL Capybara.current_driver = :webkit # login visit("https://www.facebook.com") find("#email").set("user") find("#pass").set("password") find("#loginbutton//input").click # navigate to the JS-generated page visit("www.gamename.com/...?id=12345") # parse HTML doc = Nokogiri::HTML.parse(body) 
+6
source

The easiest way is to use mechanize:

 require 'mechanize' @agent = Mechanize.new{|a| a.user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'} page = @agent.get 'http://www.facebook.com/' form = page.forms[0] form['email'], form['pass'] = ' me@myemail.com ', 'foobar' form.submit # now you're logged in and a request like this: doc = @agent.get('http://www.facebook.com/').parser # gives you a logged in Nokogiri::HTML::Document like you're used to 
+4
source

Source: https://habr.com/ru/post/910656/


All Articles