Created
June 29, 2013 15:48
-
-
Save jschoch/5891623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Tst123 do | |
def run(path) do | |
html = """ | |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" | |
"http://www.w3.org/TR/html4/strict.dtd"> | |
<HTML> | |
<HEAD> | |
<TITLE>My first HTML document</TITLE> | |
</HEAD> | |
<BODY> | |
<P>Hello world! | |
</BODY> | |
</HTML> | |
""" | |
{_,_,parsed} = :mochiweb_html.parse(html) | |
body = Enum.find(parsed, fn {"body",_,body} -> IO.inspect body; _ -> nil end ) | |
found = :mochiweb_xpath.execute(path,body) | |
{parsed,found} | |
#found = :mochiweb_xpath.execute('/html',:mochiweb_html.parse(html)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this works for .run2(path)
defmodule Tst do
def run(path) do
<TITLE>My first HTML document</TITLE>{,,parsed} = :mochiweb_html.parse(gen_html)
body = Enum.find(parsed, fn
{"body",_,body} -> IO.inspect body;
_ -> nil
end )
found = :mochiweb_xpath.execute(path,body)
{parsed,found}
#found = :mochiweb_xpath.execute('/html',:mochiweb_html.parse(html))
end
def gen_html do
html = """
Hello world! """ html end def run2(path) do found = :mochiweb_xpath.execute(path,:mochiweb_html.parse(gen_html)) end
end