Answer the question
In order to leave comments, you need to log in
How to get data from js variable using ruby?
There is an HTML file, in the body of which there is a js script, which in turn has a variable (highlighted in the photo below) that stores an array of objects.
The task is to get this HTML by reference using Ruby, and then somehow get to the treasured variable and get the array stored in it and load it into the Ruby variable for further work.
What would you recommend to use to get HTML data in Ruby?
What is the best way to get to this variable (by searching for a string by the name of the variable? Or are there any other options?)
In general, maybe someone came across such a task, help than you can ^__^
Answer the question
In order to leave comments, you need to log in
And here is an article on how to parse in Ruby, this can be done with whores and blackjack: D
https://habrahabr.ru/post/51610/
For example using Selenium WebDriver.
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :chrome
driver.get 'https://ya.ru'
result = driver.execute_script 'return Ya._metrika.hitId;'
puts result
require 'unirest'
require 'nokogiri'
response = Unirest.get 'http://example.com'
doc = Nokogiri::HTML response.raw_body
element = doc.at_css 'script' # тут нужен более точный селектор
element.text # вернёт вам сырой JavaScript
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question