How to save to disk HTMLElement ?
Closed this issue · 8 comments
How to save to disk HTMLElement ?
save to jld makes errors and exclusion julia
r = HTTPC.get(url,RequestOptions(
request_timeout=8.0,
callback=customize_curl))
page = bytestring(r.body)
doc = parsehtml(page)
body = getBody(doc) # function getBody from Your page
julia> body
HTMLElement{:body}:
Version 0.3.6 (2015-02-17 22:12 UTC)
Official http://julialang.org/ release
x86_64-w64-mingw32
Paul
you should be able to do prettyprint(io, elem)
to print a reasonably readable representation of an element to an IO (such as an open file, STDOUT, etc.)
:/
julia> prettyprint(io, body)
ERROR: UndefVarError: prettyprint not defined
help?> prettyprint
search:
Couldn't find prettyprint
Perhaps you meant prevind
julia>
W dniu 2015-03-05 o 16:51, James J Porter pisze:
you should be able to do |prettyprint(io, elem)| to print a reasonably
readable representation of an element to an IO (such as an open file,
STDOUT, etc.)—
Reply to this email directly or view it on GitHub
#11 (comment).
julia> function prettyprint(io::IO, elem::HTMLElement, maxlines)
for (i,(depth, line)) in enumerate(linesof(elem))
if i == maxlines
write(io,". . . \n")
return
else
write(io,repeat(" ",depth)line"\n")
end
end
end
prettyprint (generic function with 1 method)
julia> prettyprint(io, body)
ERROR: UndefVarError: io not defined
julia> prettyprint("io.txt", body)
ERROR: MethodError: prettyprint
has no method matching
prettyprint(::ASCIIString, ::Gumbo.HTMLElement{:body})
Closest candidates are:
prettyprint(::IO, ::Gumbo.HTMLElement{T}, ::Any)
julia> f = open("file.txt","w")
IOStream()
julia> prettyprint(f, body)
ERROR: MethodError: prettyprint
has no method matchi
Closest candidates are:
prettyprint(::IO, ::Gumbo.HTMLElement{T}, ::Any)
julia>
W dniu 2015-03-05 o 16:51, James J Porter pisze:
you should be able to do |prettyprint(io, elem)| to print a reasonably
readable representation of an element to an IO (such as an open file,
STDOUT, etc.)—
Reply to this email directly or view it on GitHub
#11 (comment).
hmmm, that is very odd, it's definitely there in the latest version (0.1.2):
julia> using Gumbo
julia> prettyprint
prettyprint (generic function with 5 methods)
julia> prettyprint(STDOUT, parsehtml("<h1>Hello, world!</h1>"))
<!DOCTYPE ><HTML>
<head></head>
<body>
<h1>Hello, world!</h1>
</body>
</HTML>
Can you paste the output of Pkg.installed("Gumbo")
?
at julia 3 is ok , julia 4 not :
_
_ _ _(_)_ | A fresh approach to technical computing
() | () () | Documentation: http://docs.julialang.org
_ _ | | __ _ | Type "help()" for help.
| | | | | | |/ ` | |
| | || | | | (| | | Version 0.4.0-dev+3600 (2015-02-25 15:26 UTC)
/ |_'|||__'| | Commit f96c23c* (13 days old master)
|__/ | x86_64-w64-mingw32
julia> Pkg.installed("Gumbo")
v"0.1.0"
julia> julia> using Gumbo
ERROR: UndefVarError: julia not defined
julia>
julia> julia> prettyprint
ERROR: UndefVarError: julia not defined
julia> using Gumbo
julia> prettyprint
ERROR: UndefVarError: prettyprint not defined
julia> prettyprint(STDOUT, parsehtml("
Hello, world!
"))ERROR: UndefVarError: prettyprint not defined
_
_ _ _(_)_ | A fresh approach to technical computing
() | () () | Documentation: http://docs.julialang.org
_ _ | | __ _ | Type "help()" for help.
| | | | | | |/ ` | |
| | || | | | (| | | Version 0.3.6 (2015-02-17 22:12 UTC)
/ |_'|||__'| | Official http://julialang.org/ release
|__/ | x86_64-w64-mingw32
julia> using Gumbo
julia> prettyprint
prettyprint (generic function with 5 methods)
julia> prettyprint(STDOUT, parsehtml("
Hello, world!
"))Hello, world!
julia>
Paul
W dniu 2015-03-08 o 19:15, James J Porter pisze:
hmmm, that is very odd, it's definitely there in the latest version
(0.1.2):|julia> using Gumbo
julia> prettyprint
prettyprint (generic function with 5 methods)julia> prettyprint(STDOUT, parsehtml("
Hello, world!
"))Hello, world!
|Can you paste the output of |Pkg.installed("Gumbo")|?
—
Reply to this email directly or view it on GitHub
#11 (comment).
As I said before, I explicitly chose not to support 0.4 while it's under development since the pace of breaking changes is so rapid; I'll make the port to 0.4 after it's released.
I'll close this for now, feel free to reopen if you find anything buggy with this on 0.3 :)