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

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -