【发布时间】:2020-02-10 07:35:33
【问题描述】:
我正在尝试恢复一个在 nokogiri 的帮助下解析网站的简单示例,并遇到一个错误 undefined method `children' for nil:NilClass (NoMethodError)
require 'open-uri'
url = 'http://www.cubecinema.com/programme'
html = open(url)
puts html
require 'nokogiri'
doc = Nokogiri::HTML(html)
showings = doc.css('.showing').map do |showing|
showing_id = showing['id'].split('_').last.to_i
tags = showing.css('.tags a')
.map{|tag| tag.text.strip}
title_el = showing.at_css('h1 a')
.children
.delete_if{|c| c.name == 'span'}
title = title_el.text.strip
dates = showing.at_css('.start_and_pricing')
.inner_html
.strip
.split('<br>')
.map(&:strip)
.map{|d| DateTime.parse(d)}
description = showing.at_css('.copy')
.text
.delete('[more...]')
.strip
{id: showing_id,
title: title,
tags: tags,
dates: dates,
description: description}
end
我找到了一个可能的解决方案https://translate.googleusercontent.com/translate_c?anno=2&depth=1&rurl=translate.google.com&sl=auto&sp=nmt4&tl=ru&u=https://github.com/dwightjack/grunt-email-boilerplate/issues/12&xid=25657,15700023,15700186,15700191,15700248,15700253&usg=ALkJrhgLkK2xqf-6SfL3K16DBRdtdNH0Cw,但不清楚 premailer 子任务是什么,阅读网站并没有真正帮助他们,我需要在哪里写下这些子任务。我将非常感谢您的澄清,无论是我的错误还是这些子任务需要如何确定的方式,我自己不理解并且缺乏经验这是可能的。
【问题讨论】:
-
这是我收到的 title_el :[nil, nil, nil...],你明白了。您正在尝试删除不存在的内容。因此错误。