开发者

Rails rake mechanize - Error - No such file to load -- Mechanize [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide aud开发者_如何学运维ience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

EDIT: Forgot to include mechanize in the gem file

I get a error that says: No such file to load -- Mechanize' when I run: rake import_stats.

My statistik.rake in lib/tasks

desc "Importer statistikker"
task :import_stats => :environment do

require 'Mechanize'
agent = WWW::Mechanize.new

agent.get("http://www.iqmedier.dk")

form = agent.page.forms.first
form.Username = 'username'
form.Password = 'password'
form.submit

agent.page.link_with(:href => "/Publisher/Stats").click
form = agent.page.forms.first
form.submit

    @stats = agent.page.search('//tr')[-2].search('td').map{ |n| n.text }
        Reklamer.create!(:virksomhed => 'Iqmedier', :dato => '(@stats[1])', :unik_klik => '(@stats[2])', :klik => '(@stats[3])', :unik_vis => '(@stats[4])', :vis => ('@stats[5]'), :leads => ('@stats[6]'), :ordre => '(@stats[6])', :cpc => '(@stats[7])', :earn => '(@stats[8])')
    end

I am trying to create a row in the table Reklamer with the scraped data.

Best regards, A rails beginner


The task name is environment, not enviroment. There's a typo. Change the line 2.


To invoke a rake task you do:

rake namespace:name_of_the_task

So in your case considering you dont have any namespace you should run:

rake import_stats

You might want a namespace, to do this you have to encapsulate the task within a namespace:

namespace :mechanize do
  task :import_stats => :environment do
    ....
  end
end

and then execute

rake mechanize:import_stats
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜