ruby - Getting specific element in Url using Nokogiri -
i have kind of html structure :
<table class="list"> <tbody> <tr> <td> </td> <td> <a href="club.do?codeclub=01670001&millesime=2015"></a> </td> </tr> </tbody> </table> i want link contained in second <td> of each <tr> contained in table has class list. in each url interested in value of codeclub : codeclub=01670001
how can achieve using nokogiri ?
you can anchor tag a using nokogiri so:
require 'nokogiri' doc = nokogiri::html.parse(<<-html_end) <table class="list"> <tbody> <tr> <td> </td> <td> <a href="club.do?codeclub=01670001&millesime=2015"></a> </td> </tr> </tbody> </table> html_end link = doc.css('table.list tbody tr td:nth-child(2) a')[0]['href'] => "club.do?codeclub=01670001&millesime=2015" then can use regular expressions entire query param of codeclub so:
link[/codeclub=([^&]*)/].gsub('codeclub=', '') => "01670001"
Comments
Post a Comment