4

I'm using Hound (with PhantomJS) to scrape a web page. The page in question lazily loads some of the content I need with Javascript.

This is what I'm doing currently.

def movies do
  Hound.start_session

  navigate_to(url())

  :timer.sleep(6000)

  # Do stuff with page_source()
end

How can I get Hound to wait for the page to be fully loaded without having to hard code an arbitrary timer?

jordelver
  • 8,292
  • 2
  • 32
  • 40
  • Possible duplicate of [Elixir Hound wait for page to load](http://stackoverflow.com/questions/37106480/elixir-hound-wait-for-page-to-load) – Cody Poll May 30 '16 at 23:36
  • This is not a duplicate. The other answer doesn't take Javascript into account. – jordelver May 31 '16 at 09:57

1 Answers1

1

not sure if its the best solution but i did this way


  def wait_until_page_is_loaded() do

    case execute_script("return document.readyState") do
       "loading" ->  wait_until_page_is_loaded()
       _ -> true
     end
  end

Piyush
  • 31
  • 2