0

我正在尝试解析doc下面变量中显示的 URL。我的问题是job变量。当我返回它时,它会返回页面上的每个职位,而不是给定评论的特定职位。有没有人建议如何返回我所指的具体职位?

require 'nokogiri'
require 'open-uri'

# Perform a google search
doc = Nokogiri::HTML(open('http://www.glassdoor.com/Reviews/Microsoft-Reviews-E1651.htm'))

reviews = []


current_review = Hash.new

doc.css('.employerReview').each do |item|
    pro = item.parent.css('p:nth-child(1) .notranslate').text
    con = item.parent.css('p:nth-child(2) .notranslate').text
    job = item.parent.css('.review-microdata-heading .i-occ').text
    puts job
    advice = item.parent.css('p:nth-child(3) .notranslate').text

    current_review = {'pro' => pro, 'con' => con, 'advice' => advice}

    reviews << current_review
end
4

1 回答 1

0

看起来像是item.parent#MainCol每种情况下,换句话说就是整个列。

更改item.parent.cssitem.css应该可以解决您的问题。

于 2013-04-28T02:07:51.703 回答