質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

Q&A

0回答

1017閲覧

データベースにスクレイピングしてきた情報をカラムに保存したい

退会済みユーザー

退会済みユーザー

総合スコア0

Ruby

Rubyはプログラミング言語のひとつで、オープンソース、オブジェクト指向のプログラミング開発に対応しています。

0グッド

0クリップ

投稿2018/12/12 04:53

前提・実現したいこと

具体的に何が原因になっていて、どのような処理をすればいいのでしょうか?

発生している問題・エラーメッセージ

NameError: undefined local variable or method `director' for Scraping:Class from /projects/mooovi/app/models/scraping.rb:29:in `get_product'

該当のソースコード

class Scraping
def self.movie_urls
links = []
agent = Mechanize.new
next_url = ""

while true current_page = agent.get("http://review-movie.herokuapp.com/" + next_url) elements = current_page.search('.entry-title a') elements.each do |ele| links << ele.get_attribute('href') end next_link = current_page.at('.pagination .next a') break unless next_link next_url = next_link.get_attribute('href') end links.each do |link| get_product('http://review-movie.herokuapp.com' + link) end

end

def self.get_product(link)
agent = Mechanize.new
page = agent.get(link)
title = page.at('.entry-title').inner_text if page.at('.entry-title')
image_url = page.at('.entry-content img')[:src] if page.at('.entry-content img')
product = Product.where(director: director, detail: detail, open_date: open_date).first_or_initialize
product.director = director
product.detail = detail
product.open_date = open_date
product.save
end
end

Ruby

試したこと

全角のスペースを探した

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問