Alex Zakruzhetskyi Alex Zakruzhetskyi - 24 days ago 8
Ruby Question

Get <a> content via Nokogiri

I'm trying to get a content of

<a>
element via
Nokogiri
by doing the following:

novelty.title = page.at_css('h1 a')


It saving to database like this:
<a href="a_link_to_a_novelty_title">A title</a>
. So, how can I get only
A title
from the
<a>
tag? Thanks.

Answer

You can write as below to get the text.

ovelty.title = page.at_css('h1 a').text