pillaiindu

pillaiindu

Hi Everyone!

I want to do some web scraping, for which I wanna use the hound package as it have everything required for web scraping.
I know how to use it in a Phoenix project for testing, which I learnt from Phoenix inside out, thanks to @shankardevy. In a Phoenix project we had to put config :hound, driver: "phantomjs" in config/config.exs, if we were using phantomjs.

But here the situation is a bit different.

  1. Its not a Phoenix project.
  2. I want to use it in a file inside lib/ not test/, as this time I’m using it for web-scraping instead of testing.

Thank you!

Showing Posts 1 to 10

NobbZ

NobbZ

It should just work…

Make sure its not runtime: false and not only: :test in your deps.

pillaiindu

pillaiindu OP

Yes, the runtime: false and only: :test isn’t there.

Following is my code:

defmodule Scrap do
  use Hound.Helpers


  def start do
    IO.puts "starting"
    Hound.start_session()
    navigate_to("https://somewebsite.com/sign-in")
    find_element(:name, "email") |> fill_field("someone@something.com")
    find_element(:name, "password") |> fill_field("somepassword")
    find_element(:type, "submit") |> click()
    IO.puts "Logged in!"
  end
end

And this is the error

iex(1)> Scrap.start
starting

14:21:57.299 [error] GenServer Hound.SessionServer terminating
** (RuntimeError) could not create a new session: econnrefused, check webdriver is running
    (hound) lib/hound/session_server.ex:101: Hound.SessionServer.create_session/2
    (hound) lib/hound/session_server.ex:78: Hound.SessionServer.handle_call/3
    (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.208.0>): {:change_session, #PID<0.208.0>, :default, []}
State: %{}
Client #PID<0.208.0> is alive

    (stdlib) gen.erl:167: :gen.do_call/4
    (elixir) lib/gen_server.ex:1006: GenServer.call/3
    (scrap) lib/scrap.ex:7: Scrap.start/0
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) src/elixir.erl:275: :elixir.eval_forms/4
    (iex) lib/iex/evaluator.ex:257: IEx.Evaluator.handle_eval/5
    (iex) lib/iex/evaluator.ex:237: IEx.Evaluator.do_eval/3
    (iex) lib/iex/evaluator.ex:215: IEx.Evaluator.eval/3
** (exit) exited in: GenServer.call(Hound.SessionServer, {:change_session, #PID<0.208.0>, :default, []}, 60000)
    ** (EXIT) an exception was raised:
        ** (RuntimeError) could not create a new session: econnrefused, check webdriver is running
            (hound) lib/hound/session_server.ex:101: Hound.SessionServer.create_session/2
            (hound) lib/hound/session_server.ex:78: Hound.SessionServer.handle_call/3
            (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
            (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
            (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
    (elixir) lib/gen_server.ex:1009: GenServer.call/3
    (scrap) lib/scrap.ex:7: Scrap.start/0
iex(1)>
NobbZ

NobbZ

Looks like :hound hasn’t been started.

How do you start iex and how does your application/1 in mix.exs look like?

wolfiton

wolfiton

You don’t have a webdriver running for example phantomjs --wd

This error here is what i posted above in case you want a ref

** (RuntimeError) could not create a new session: econnrefused, check webdriver is running
NobbZ

NobbZ

I was under the assumption that hound would handle the lifecycle

wolfiton

wolfiton

No it doesn’t on it’s own it needs a web driver selenium or phantomjs like help

From the docs 
When you run `mix test` , Hound is automatically started. **You'll need a webdriver server** 
running, like Selenium Server or Chrome Driver. If you aren't sure what it is, then 
[read this](https://github.com/HashNuke/hound/wiki/Starting-a-webdriver-server).
pillaiindu

pillaiindu OP

I’m running the webdriver, but may be it’s not finding it, or may be I need to tell it explicitly like we do in the Phoenix apps.

➜  bin ./phantomjs --wd
[INFO  - 2020-01-11T12:41:45.744Z] GhostDriver - Main - running on port 8910
wolfiton

wolfiton

I have only used it for testing. Someone else tried using it for receiving content from a page but worked to a certain point you can see our discussion here:

NobbZ

NobbZ

Again, please tell us how you start the iex session from where you try to play with hound.

Also from that same iex session, please do Application.get_env(:hound, :driver).

If it is returning something else than "phantomjs", your configuration is not set up properly.

pillaiindu

pillaiindu OP

It says nil

iex(1)> Application.get_env(:hound, :driver)
nil

Looks like I need to add the config somewhere.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews