0

How do I get the HTML of a page after JavaScript has executed?

For testing parser – test page.

I use Nokogiri. But that only gives me the HTML source.

1
  • 1
    Turn off JavaScript in your browser. Look at the page's source. That's what Nokogiri will see. It takes something with a JavaScript interpreter to do what you want. Commented Apr 27, 2015 at 18:27

2 Answers 2

1

You need to use some sort of environment that evaluates Javascript, which Nokogiri does not do.

Some examples:

Each of these has pros and cons, without more details I can't really tell you which would be better. You can always just try each one and figure out which one works better for you.

Keep in mind that doing this at scale for sites like Yelp will result in you getting blocked.

Sign up to request clarification or add additional context in comments.

Comments

0

You cannot do it. Javascript is executed by browser. Once rails deliver the html to browser you don't have access to it. I think you want something like Capybara, Selenium, etc, to test your code. See this: http://www.opinionatedprogrammer.com/2011/02/capybara-and-selenium-with-rspec-and-rails-3/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.