Gem nokogiri html 如何获取 input value 值 (已解决)

zhq_zhq · September 16, 2014 · Last by zhq_zhq replied at September 16, 2014 · 2748 hits

html 页面代码

<input id="featured_item_id" type="hidden" value="37545306978">

代码

def self.get_uri(product_id) 
    url = "http://zpzk100.com/details/#{product_id}"

    resp = RestClient.get("http://zpzk100.com/details/#{product_id}")
    html = Nokogiri::HTML(resp)
    href = html.css('.goto').attr('href').text
    uri = URI.parse(URI.encode(href.strip))
    resp = RestClient.get(uri)
    html = Nokogiri::HTML(resp)
    #获取input值
    html.at('input#featured_item_id').map{|node| node["value"]}
end
id = html.css('#featured_item_id').map{|u| u['value']}.first (已取出谢谢)
You need to Sign in before reply, if you don't have an account, please Sign up first.