使用 Nokogiri (json?) rake 任务保存到数据库

Saving to a database using a Nokogiri (json?) rake task

这里是 RoR 菜鸟!我有一个 rake 任务正在做我想做的事情我只是想知道如何将结果保存到我的 language table。我希望这个 rake 任务的结果填充我的 language table 上 language 字段的值。我愿意接受任何建议(比如在这里使用 json)

namespace :scraper do
  desc "Scraper"
  task scrape: :environment do

require 'open-uri'
require 'nokogiri'
require 'csv'
require 'json'

url = "https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers"
page = Nokogiri::HTML(open(url))  
page.css('td b a').each do |line|
 puts line.text
end
end
namespace :scraper do
  desc "Scraper"
  task scrape: :environment do
    require 'open-uri'
    require 'nokogiri'
    require 'csv'
    require 'json'

    url = "https://en.wikipedia.org/wiki/List_of_languages_by_number_of_native_speakers"
    page = Nokogiri::HTML(open(url))  
    page.css('td b a').each do |line|
      puts line.text  # "Spanish" 
      Language.create(language: line.text)
    end
  end
end