M
M
Magic Code2020-07-23 13:17:32
ruby
Magic Code, 2020-07-23 13:17:32

Why is Nokogiri returning an empty array?

Good health, dear ones!
I'm trying to parse the hh.ru page, but why it doesn't work, please tell me what I'm doing wrong:

require 'nokogiri'
require 'rubygems'
require 'open-uri'

leaf = 0
count = Array.new
until leaf > 2
  url = "https://rostov.hh.ru/search/vacancy?L_is_autosearch=false&area=113&clusters=true&enable_snippets=true&order_by=publication_time&schedule=remote&page=#{leaf}"
  page = Nokogiri::HTML(open(url))
  element = page.css('div').select { |e| e['class'] == 'vacancy-serp-item' }
  p element
  leaf += 1
  count << links
end

Also, I tried to parse using HTTParty, specifying the same class, but all by.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GeneAYak, 2020-07-25
@Panda_Code

you can immediately search by the selector, for example: in this way you will have an array of nodes that can already be processed to extract specific information
page.css('div.vacancy-serp-item')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question