这似乎是一个显而易见的问题,但我是个新手。我正在尝试从Rotten Tomatoes top 100 movie列表中获取一个简单的CLI应用程序。一切都很顺利,直到Herer.link行,在那里我得到了nilClass的一个未定义的方法‘属性’。我只是想知道标题链接的href的值。我已经尝试了我理解的所有方法,甚至更多,但我就是想不出如何在不使用属性方法的情况下访问我想要的东西。
然而,当我在函数中间使用Pry时,我可以手动键入它,它似乎起作用了。
def new_with_rank
self.get_top_page.css(".table tr").each do |e|
hero = Top100::Movie.new
hero.rank = e.css(".bold").text.delete!(".")
binding.pry
hero.rating = e.css(".tMeterScore").text.gsub!(/\u00A0/, "")
hero.title = e.css(".unstyled").text
hero.title.strip! #Don't know why I can't chain onto .text above
hero.reviews = e.css("td.right.hidden-xs").text
hero.link = e.css("td a").attribute("href").value
end
Top100::Movie.all.shift
Top100::Movie.all
binding.pry
end
谢谢你的帮助。
1条答案
按热度按时间mspsb9vt1#
对于将来,建议使用以下方法来调试循环: