How to parse JavaScript using Nokogiri and Ruby
If I read you correctly you're trying to parse the JavaScript and get a Ruby array with your image URLs yes?
Nokogiri only parses HTML/XML so you're going to need a different library; A cursory search turns up the RKelly library which has a parse
function that takes a JavaScript string and returns a parse tree.
Once you have a parse tree you're going to need to traverse it and find the nodes of interest by name (e.g. _arPic
) then get the string content on the other side of the assignment.
Alternatively, if it doesn't have to be too robust (and it wouldn't be) you can just use a regex to search the JavaScript if possible:
/^\s*_arPic\[\d\] = "(.+)";$/
might be a good starter regex.
How to parse a JavaScript-based page
You need to use a Watir gem for this one since it is loaded through ajax.
And also, it seems they have an API, you may also want to take look at this.
How can I use JavaScript to parse Ruby JSON string
Why don't you do:
data = <%= @chromosomes.html_safe %>;
Sidenote:
I hope you do something like:
@chromosomes = [{ name: "YHet", organism_id: "foo" }].to_json
What tools exist for parsing Javascript and reading the results in Javascript or Ruby?
Check out UglifyJS: https://github.com/mishoo/UglifyJS
Parse ruby object in JavaScript (Rails)
JSON is valid Javascript right out of the box, so why not just do:
var js_obj = <%= @rails_obj.to_json %>;
Markdown parser in Javascript
Showdown? -
The http://attacklab.net/showdown/ site is defunct.
Showdown is now available on git, here: https://github.com/coreyti/showdown
Related Topics
JavaScript Detect Click Event Outside of Div
JavaScript Error Null Is Not an Object
Mui Createtheme Is Not Properly Passing Theme to Mui Components
How to Optimize Website for Touch Devices
How to Do Page Numbering in Header/Footer HTMLs with Wkhtmltopdf
Jquery Parallax Scrolling Effect - Multi Directional
Ios8 Safari After a Pushstate the :Nth-Child() Selectors Not Works
How to Access Styles from React
How to Zoom a Background Image on a Div with Background-Size
Calculate Color Values from Green to Red
How to Inject a Style with an "!Important" Rule
How to Make My Navbar Change CSS Class Upon Scrolling Past an Anchor Point
Using Masonry with Imagesloaded
Delay Removing a Class in Jquery
Find the "Potential" Width of a Hidden Element
Detecting Flex-Wrap Support in Browsers
How to Tell When a CSS Background Image Has Loaded? Is an Event Fired