M
M
Magic Code2020-10-22 18:34:47
ruby
Magic Code, 2020-10-22 18:34:47

How to get the value of each 3-element?

Guys, hello!

Here is the code I wrote:

require 'nokogiri'
require 'open-uri'


url = 'https://zakupki.gov.ru/epz/order/extendedsearch/results.html'
document = Nokogiri::HTML(URI.open(url))

document.css('div.data-block__value').each do |link|
  0.step(link.content.length, 2) do |v|
    puts link.content[v]
  end
end

But, it's not quite the same! I need to display the value of each 3 elements, in python it's like this:
values = soup.find_all('div', class_='data-block__value')

for i in range(2, len(values), 3):
    print(values[i])

And, as in rubles, tell me)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valentin V., 2020-10-22
@Panda_Code

document.css('div.data-block__value').each_with_index do |link, i|
  puts link.content[v]  if (i + 1) % 3 == 0
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question