Nokogiri刮ing

问题描述 投票:-1回答:1

我想剪贴每个视频的标题和链接。

doc = Nokogiri::HTML(open('http://www.stream2u.me/'))
doc.css('.lshpanel').each do |link|
  binding.pry
  puts link.elements[1].text
  puts "LINKS ARE: "
  ## Cant figure out how to get to the links...
end

有人可以帮忙!在它上工作了一个小时,无法解决。

ruby nokogiri
1个回答
1
投票

您可以使用css方法找到链接,然后遍历集合以提取href属性。例如:

require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML(open('http://www.stream2u.me/'))

doc.css('.lshpanel').each do |d| 
  puts d.css('.lshevent').text
  d.css('a').each { |el| puts el['href'] }
end
© www.soinside.com 2019 - 2024. All rights reserved.