Is there a way to choose the following element within Nokogiri without utilizing the "next_element" method?

Upon running my code on a different machine, I encountered the following issue: Error: ruby: symbol lookup error: /usr/local/ruby/lib/ruby/gems/2.1.0/gems/nokogiri-1.6.7.2/lib/nokogiri/nokogiri.so: undefined symbol: xmlNextElementSibling

At the start of the process, a warning appeared: WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded 2.6.30 As I am unable to update nokogiri at this moment, I delved into the source code only to discover that the issue lies with the next_element method used by Nokogiri, which functions correctly on my machine but fails on the other. Therefore, my query is how can I efficiently select the next HTML element (specifically, the next "tr" in a table)?

This is the current code snippet I am utilizing:

def get_weight(spot)

      frame = spot.at_css("table[id='1']").css("tr")[1]
      starter = frame.at('tr:contains("D7r5")') 
      return nil if starter == nil
      starter = starter.next_element
      peso = []
      until starter.css("td")[1].nil?          
        data = starter.css("td")[1].inner_html.gsub(/\t{0..100}/, "").strip
        ndecimal = data.scan(/[0-9]{1,4},?.?[0-9]{0,3}/).last.gsub(",", ".")
        nmeasure = data.scan(/[kK][Gg]|\s[g]\s|[g]/).last
        case nmeasure
        when (/[kK][Gg]/)
          peso << ndecimal.to_f
        when (/g|\s[g]\s|[g]/)
          peso << ndecimal.to_f / 1000
        end 
        starter.next_element.nil? ? break : starter = starter.next_element
        end 
        return peso.max == 0 ? nil : peso.max
  end

Answer №1

The XPath equivalent to next_element is following-sibling::*[1]. Alternatively, you can use following-sibling::* if the XPath will be executed using something like at_xpath(), which only returns the first matched node by default.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Show active Main Menu and sub Menu through the use of CSS and javascript

I currently have left side menus. <div class="panel"> <div class="panel-heading panel-red" role="tab" id="headingDash" style=""> <a role="button" data-toggle="collapse" data-parent="#accordionMenu" href="#collapseDash" aria-expa ...

Managing a fixed footer in an Android webview to prevent it from obstructing an input field when the soft keyboard appears

I am working with a webview that contains a React app, not React Native. The webview features a login page with two input fields and a fixed footer. However, when one of the input fields is focused, the footer moves up and covers part of the input field, ...

Troubleshooting: Why is PHP/HTML Code Displaying as Text in Email?

I have made numerous attempts to modify the header without success. Could it possibly be an issue with the email server? Or is there a crucial aspect that I'm overlooking? I would appreciate if more than just the code appears as plain text in the fi ...

What could be causing a CSS transition to fail when hovering over a different image source?

Looking to change the image source of an <a> tag when hovering over it, while also incorporating a transition effect. It seems that the transition effect is effective with the background-image property for a <div> tag, but not with the conten ...

The error message displayed at selenium/webdriver/firefox/binary.rb:134 says that we cannot make changes to a frozen String due to the FrozenError

I attempted to execute a basic Google search script using Selenium on an EC2 instance running Amazon Linux. However, I encountered an issue while trying to launch Firefox and am struggling to decipher the error message. Here are the versions of Ruby and s ...

Creating a text container in PHP for displaying information

As someone who is new to PHP and HTML, I'm curious about the CSS statements needed to create a text box that will display a value from one of my PHP functions. Right now, the function retrieves data from an SQL server and returns it, but I would like ...

Website not employing CSS or JQuery on its server

After creating my site, I tested it locally using XAMPP and it worked perfectly. However, when I hosted it, the CSS and JQuery (Google library) stopped working altogether. The CSS tags are using the standard format: <link rel="stylesheet" type="text/c ...

Is CSS being dynamically generated by style?

I have a website that I need help with: The footer on my site is currently black and I want to remove it To fix this issue, I have to adjust the height in this line of code <div style="position: relative; height: 126px;" id="footer-sidebar" class="fo ...

How to Customize Bootstrap Colors Globally in Angular 4 Using Code

I am interested in developing a dynamic coloring system using Angular. I have set up a service with four predefined strings: success, info, warning, and danger, each assigned default color codes. My goal is to inject this service at the root of my applicat ...

The quirk of the Ruby JSON parse method lies in its unique instance variable

It's strange, sometimes when I use JSON.parse and assign the result to a variable, later in my app that variable ends up being NilClass. What's going on? Let's consider this code snippet: require 'rest-client' class Foo attr_ ...

Can anyone suggest a stellar sprite generator for me?

I am in search of a sprite generator to streamline my web development process. With so many options available, I am seeking recommendations for the best tool. Ideally, I want a generator that can produce both a sprite image and corresponding CSS files wi ...

Tips for handling CSS loading delays with icons in OpenLayers markers

When using openlayers (v4.6.4) with font-awesome as marker icons, the icons do not display upon first load (even after clearing cache and hard reload). Instead, I see a rectangle resembling a broken character. It is only on the second load that they appear ...

Personalized Bootstrap 4 grid system

Could someone guide me on how to create this grid layout with Bootstrap 4? I am trying to achieve a design where one column stretches from the edge of the window to the inside, while the other column is half the width of a standard .container element. ht ...

Display PDF on a separate tab when button is clicked in HTML

Is there a way to open a PDF in a new tab or window when a button is clicked? I've tried using onclick="window.location.href" but it always opens the PDF in the same page. Here's my code: <input type="button" value="Report" onclick="location ...

Three.js combined with Ember.js

I've been brainstorming ways to merge Ember.js with Three.js. My goal is to render multiple elements, manage the data with Ember.js bindings and general pub/sub handling, while also being able to manipulate the views/elements with three.js using THREE ...

Adjusting the transparency of a div's background using RGBa

I am currently working on adjusting the background opacity of a div using a jquery ui slider. Allowing users to modify the background color of the div, I am seeking guidance on how to adjust only the alpha parameter of the background while keeping the col ...

Is there a way to resolve this issue without the need for responsiveness?

I have been using the card element in Bootstrap, but I noticed that when I zoom in, the heights of these 3 cards become different due to the card title. Is there a way to fix this without relying on responsive techniques like @media queries? Below is my H ...

What is the reason behind the different vertical behavior of float and inline-block elements?

Check out my code example here. I've created a div with an i element inside. I set the i element's width and height attributes in a unique way, which has led to a line-height issue. While I have some knowledge about the difference between using ...

Struggling with passing values to onClickHandler because of MUI

I'm looking to create a category navigation menu that includes icons and labels. I attempted to do this using Chips: {categories.map((category) => ( <Chip key={category._id} ...

Applying a translucent layer of color to a jpeg image to create a subtle background effect

I am attempting to create a semi-transparent, solid background color on top of an <img> tag, while still showing the original image underneath at the same ratio and size. Below is a snippet of the code I am working with (let me know if you need more ...