-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscraper.ex
More file actions
56 lines (50 loc) · 1.57 KB
/
scraper.ex
File metadata and controls
56 lines (50 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
defmodule Scraper do
use Hound.Helpers
def start do
# List of additional args here: http://peter.sh/experiments/chromium-command-line-switches/
Hound.start_session(
browser: "chrome",
user_agent: :chrome,
driver:
%{
chromeOptions:
%{
args: [
"--incognito",
"--window-size=1280,1024",
"--window-position=0,0"
],
prefs: %{
"profile.default_content_settings.popups" => 2,
"profile.managed_default_content_settings.geolocation" => 0
}
}
}
)
navigate_to "https://www.dom.com/"
# If the host machine is located in Virginia, the dom server will
# automatically route the browser to the Virginia page. In cases where it
# doesn't, let's switch to Virginia
if element?(:link_text, "Other") do
find_element(:link_text, "Other") |> click
find_element(:id, "VA") |> click
end
find_element(:id, "user") |> fill_field(System.get_env("DOM_USERNAME"))
find_element(:id, "password") |> fill_field(System.get_env("DOM_PASSWORD"))
find_element(:id, "SignIn") |> click
find_element(:link_text, "Analyze Energy Usage") |> click
tmp = page_source() |>
Floki.find("#paymentsTable") |>
Floki.find("tr") |>
tl |> # tl grabs the tail of a list
Enum.at(0) |> # grabs the tr
Floki.find("td") |>
Enum.at(0) |>
elem(2) |>
Floki.text |>
String.strip
end
def stop do
Hound.end_session
end
end