task :fetch_front => :environment do
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'mechanize'
agent = Mechanize.new
agent.get("http://www.reddit.com/")
agent.page.search("a.title").each do |thread|
thread.click
end
end
I am using mechanize to go into each reddit thread on the first page and return the top comment for each thread. The 'thread' block in the each method returns the link for each reddit thread. The problem is I am not sure how to click into the thread and return the top comment for each thread.
With my current code, it is returning an undefined method click
error when I attempt to click into each thread to display the comments.