-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add parser of html links #87
Changes from 5 commits
c55daf8
5c36f40
9c9a668
17612b2
6d7a44f
7d55762
fff0bb9
def56d9
6422b03
9d48de1
14a3f1a
f38c140
2b8df13
d5b753c
5068ba6
af9da82
57f681c
ae8dc30
4a53137
485c904
792a512
36a9324
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule Parser do | ||
def html_links(document) do | ||
Floki.parse_document!(document) | ||
|> Floki.find("a") | ||
|> Floki.attribute("href") | ||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,10 @@ defmodule Onigumo.MixProject do | |||||
# {:dep_from_hexpm, "~> 0.3.0"}, | ||||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, | ||||||
{:httpoison, "~> 1.8"}, | ||||||
{:mox, "~> 1.0", only: :test} | ||||||
{:mox, "~> 1.0", only: :test}, | ||||||
|
||||||
# Toolbox dependencies | ||||||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{:floki, "~> 0.32.0"} | ||||||
Glutexo marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do we want to specify the latest version at the creation of the pull request or round it down to zero? What is the convention? Answer: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you mentioned that in #161 (comment). |
||||||
] | ||||||
end | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule ParseTest do | ||
use ExUnit.Case | ||
|
||
@urls [ | ||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"http://onigumo.local/hello.html", | ||
"http://onigumo.local/bye.html" | ||
] | ||
|
||
test("Parsing values of href attributes in html links") do | ||
document = ~s("<!doctype html> | ||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<html> | ||
<body> | ||
<section id="content"> | ||
<p class="headline">Floki</p> | ||
<a href="http://onigumo.local/hello.html">Hello</a> | ||
<a href="http://onigumo.local/bye.html">Bye</a> | ||
<span data-model="user">onigumo</span> | ||
</section> | ||
</body> | ||
</html>") | ||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result = Parser.html_links(document) | ||
nappex marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert result == @urls | ||
end | ||
end |
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤨