Is there anyway to search and get the value of <a>.. </a>?
Asked Answered
C

1

1

In a webpage suppose i have the below values:

<td> <a href="https://www.test.com/test123/a.html"> test11 </a> </td>
<td> <a href="https://www.test.com/test12333/r.html"> test12 </a> </td>
<td> <a href="https://www.test.com/testaa123/t.html"> test21 </a> </td>
<td> <a href="https://www.test.com/test123123/b.html"> test31 </a> </td>

Is there anyway to find the value test21 using Ruby?

Or is there anyway to find the href values which has a substring /testaa123/t.html?

Cq answered 20/1, 2013 at 19:18 Comment(2)
Can anyone help me here?Cq
Is there any way you can provide sample code showing what you've written?Agbogla
I
1

Try out this tutorial for Nokogiri.

Example for a <li> tag:

require 'rubygems'
require 'nokogiri'   
require 'open-uri'
PAGE_URL = "http://ruby.bastardsbook.com/files/hello-webpage.html"

page.css('li')[0].text

This will output YouTube from the site below:

<div id="funstuff">
   <p>Here are some entertaining links:</p>
   <ul>
      <li><a href="http://youtube.com">YouTube</a></li>
      <li><a data-category="news" href="http://reddit.com">Reddit</a></li>
      <li><a href="http://kathack.com/">Kathack</a></li>
      <li><a data-category="news" href="http://www.nytimes.com">New York Times</a></li>
  </ul>
</div>
Ibbie answered 20/1, 2013 at 19:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.