Skip to content
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

Error accessing node content using "nodecontent" #105

Closed
aqqdgyz opened this issue Apr 8, 2019 · 8 comments
Closed

Error accessing node content using "nodecontent" #105

aqqdgyz opened this issue Apr 8, 2019 · 8 comments

Comments

@aqqdgyz
Copy link

aqqdgyz commented Apr 8, 2019

Hi, I tried to access the content of node using "nodecontent", an error message is "ERROR: LoadError: AssertionError: isempty(XML_GLOBAL_ERROR_STACK)"

so, i modify "nodecontent" as this:

function nodecontent(node::EzXML.Node)
    str_ptr = ccall(
        (:xmlNodeGetContent, EzXML.libxml2),
        Cstring,
        (Ptr{Cvoid},),
        node.ptr)
    str = unsafe_string(str_ptr)
    Libc.free(str_ptr)
    return str
end

And then my code looks right

@bicycle1885
Copy link
Member

Could you show me your code that can reproduce the problem? I think this problem happens when you somehow ignore other errors or due to an internal bug of EzXML.jl.

@aqqdgyz
Copy link
Author

aqqdgyz commented Apr 9, 2019

push!(LOAD_PATH, ".")
import QCURL
using EzXML

function nodecontent(node::EzXML.Node)
    str_ptr = ccall(
        (:xmlNodeGetContent, EzXML.libxml2),
        Cstring,
        (Ptr{Cvoid},),
        node.ptr)
    str = unsafe_string(str_ptr)
    Libc.free(str_ptr)
    return str
end

function baidu(kw::String)
    reqs = Array{QCURL.RequestDesc}(undef, 0)
    for i in 1:1
        req = QCURL.RequestDesc()
        req.url = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=2&tn=baiduhome_pg&wd=$kw&rsv_spt=1&rsv_sug1=1&rsv_sug4=1395&rn=50&pn=$(50 * (i -1))"
        req.method="GET"
        push!(reqs, req)
    end
    QCURL.request_from_list(reqs)
    for req in reqs
        doc = parsehtml(req.response.text)
        hrefs = findall("/html/body/div[@id='wrapper']/div[@id='wrapper_wrapper']/div[@id='container']/div[@id='content_left']/div[@class='result c-container ']/h3/a",doc)
        titles = findall("/html/body/div[@id='wrapper']/div[@id='wrapper_wrapper']/div[@id='container']/div[@id='content_left']/div[@class='result c-container ']/h3/a/em",doc)
        for item in hrefs
            println(nodecontent(item))
        end
    end
end
baidu("测试")

@bicycle1885
Copy link
Member

Please quote code with triple backquotes or you'll ping someone else with macros and other @ characters. https://guides.github.com/features/mastering-markdown/

@aqqdgyz
Copy link
Author

aqqdgyz commented Apr 9, 2019

I guess the problem occurred in the @check macro

@bicycle1885
Copy link
Member

Do you see any other errors or warnings except this?

@aqqdgyz
Copy link
Author

aqqdgyz commented Apr 9, 2019

This is the complete error message:

ERROR: LoadError: AssertionError: isempty(XML_GLOBAL_ERROR_STACK)
Stacktrace:
 [1] macro expansion at C:\Users\X\.juliapro\JuliaPro_v1.0.3.1\packages\EzXML\r19gO\src\error.jl:49 [inlined]
 [2] nodecontent(::EzXML.Node) at C:\Users\X\.juliapro\JuliaPro_v1.0.3.1\packages\EzXML\r19gO\src\node.jl:1120
 [3] baidu(::String) at D:\Projects\Julia\OSINT.jl:34
 [4] top-level scope at none:0
 [5] include at .\boot.jl:317 [inlined]
 [6] include_relative(::Module, ::String) at .\loading.jl:1044
 [7] include(::Module, ::String) at .\sysimg.jl:29
 [8] exec_options(::Base.JLOptions) at .\client.jl:266
 [9] _start() at .\client.jl:425
in expression starting at D:\Projects\Julia\OSINT.jl:39

@bicycle1885
Copy link
Member

Yeah, I know. I think you may perhaps see other errors or warnings before this message, because EzXML.jl is supposed to capture all errors that happen internally. The error you reported will happen when there are errors in the global error stack that are somehow not handled properly.

@aqqdgyz
Copy link
Author

aqqdgyz commented Apr 9, 2019

Okay, I'll check my code. Thank you.

@aqqdgyz aqqdgyz closed this as completed Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants