Skip to content

Instantly share code, notes, and snippets.

@johndel
Last active April 25, 2018 06:35
Show Gist options
  • Save johndel/29afec4b159203baf7521cd5a50dbb60 to your computer and use it in GitHub Desktop.
Save johndel/29afec4b159203baf7521cd5a50dbb60 to your computer and use it in GitHub Desktop.

Revisions

  1. johndel revised this gist Aug 5, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions check_friends_headless.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    require 'mechanize'

    fb_friends = []

    # login
    agent = Mechanize.new
    page = agent.get("https://www.facebook.com")
  2. johndel created this gist Aug 5, 2016.
    24 changes: 24 additions & 0 deletions check_friends_headless.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    require 'mechanize'

    # login
    agent = Mechanize.new
    page = agent.get("https://www.facebook.com")
    next_page = page.form_with(:id => 'login_form') do |form|
    form.field_with(:id => 'email').value = 'username'
    form.field_with(:id => 'pass').value = 'password'
    end.submit

    i = 0
    while true do
    page2 = agent.get("https://touch.facebook.com/profile.php?v=friends&startindex=#{i}")
    if page2.search("h3 a").count != 0
    page2.search("h3 a").each do |link|
    fb_friends << link.children.first.text
    end
    i = i + page2.search("h3 a").count
    else
    break
    end
    end

    fb_friends = fb_friends.uniq