require "nokogiri"
Nokogiri::HTML.parse(<<_).css("body").children.first.text
<body>
text <br/>
<ul>
<li>some more text </li>
</body>
_
# => "\ntext "
Nokogiri::HTML.parse(<<_).css("body").children.first.text.strip
<body>
text <br/>
<ul>
<li>some more text </li>
</body>
_
# => "text"
How to parse HTML using nokogiri if the required content doesn't have a class or id? [closed]
-
19-06-2023 - |
Question
I am trying to scrape some content and parse it using Nokogiri! Got struck now since i am trying to get some text content which is not enclosed with in any kind of tags. Just text and some of it in tags with out any class or id to it.
Can i find content by searching just the content/text starting and ending of it and get all of it in between?
<body>
text <br/>
<ul>
<li>some more text </li>
</body>
CSS selectors or Xpath, any solution would be great.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow