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

Exception at 0x1e34a6, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance) #136

Closed
donglu opened this issue Apr 6, 2018 · 7 comments

Comments

@donglu
Copy link

donglu commented Apr 6, 2018

html is: "<p class="name" style="padding-left: 5px;">\n\t\t\t\t\t<a href="javascript:;" class="pic" onclick="ToPdfReadBook(13863989,0)" style="font-size: 14px;" title="经济学 微观部分">《经济学  微观部分》\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t

"

when i use
myhtml_collection_t *text=myhtml_get_nodes_by_tag_id_in_scope(tree,NULL,classname_list->list[i]->child,MyHTML_TAG__TEXT, NULL);
const char *t=myhtml_node_text(text->list[0],NULL);

then error code is show in debug view.
i want to known the reason.Please help me

@lexborisov
Copy link
Owner

lexborisov commented Apr 6, 2018

I need to know what to contain in classname_list and you can check for NULL value:

if (classname_list->list[i]->child != NULL) {
    myhtml_collection_t *text = myhtml_get_nodes_by_tag_id_in_scope(tree, NULL, classname_list->list[i]->child, MyHTML_TAG__TEXT, NULL);

    if (text != NULL && text.length != 0) {
        const char *t = myhtml_node_text(text->list[0], NULL);
        /* do what you want */
    }

    myhtml_collection_destroy(text);
}

@donglu
Copy link
Author

donglu commented Apr 7, 2018

classname_list is get as follows:
myhtml_collection_t *classname_list=myhtml_get_nodes_by_attribute_value(tree,NULL,NULL,false,"class",strlen("class"),"name",strlen("name"),NULL);
it's not NULL.

@donglu
Copy link
Author

donglu commented Apr 7, 2018

May be it's a problem of html encoding?

@lexborisov
Copy link
Owner

This code work fine:

    const char* data = "<p class=\"name\" style=\"padding-left: 5px;\">\n\t\t\t\t\t<a href=\"javascript:;\" class=\"pic\" onclick=\"ToPdfReadBook(13863989,0)\" style=\"font-size: 14px;\" title=\"经济学 微观部分\">《经济学  微观部分》\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t";
    
    myhtml_t* myhtml = myhtml_create();
    myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 2, 0);
    
    myhtml_tree_t* tree = myhtml_tree_create();
    myhtml_tree_init(tree, myhtml);
    
    myhtml_parse(tree, MyENCODING_UTF_8, data, strlen(data));
    
    myhtml_collection_t *classname_list = myhtml_get_nodes_by_attribute_value(tree, NULL, NULL, false, "class", strlen("class"), "name", strlen("name"), NULL);
    
    for (size_t i = 0 ; i < classname_list->length; i++) {
        myhtml_collection_t *text = myhtml_get_nodes_by_tag_id_in_scope(tree, NULL, classname_list->list[i], MyHTML_TAG__TEXT, NULL);
        
        for (size_t j = 0 ; j < text->length; j++) {
            const char *t = myhtml_node_text(text->list[j], NULL);
            printf("%s\n", t);
        }
        
        myhtml_collection_destroy(text);
    }
    
    myhtml_collection_destroy(classname_list);
    
    myhtml_tree_destroy(tree);
    myhtml_destroy(myhtml);

in myhtml_get_nodes_by_tag_id_in_scope not child, this is scope node.

@donglu
Copy link
Author

donglu commented Apr 7, 2018

Problem solved, Thanks!

@donglu
Copy link
Author

donglu commented Apr 7, 2018

another problem, the code as follows:
const char* data = "<p class="name" style="padding-left: 5px;"> <a href="javascript:;" class="pic" onclick="ToPdfReadBook(13863989,0)" style="font-size: 14px;" title="经济学 微观部分">《经济学  微观部分》

";

myhtml_t* myhtml = myhtml_create();
myhtml_init(myhtml, MyHTML_OPTIONS_DEFAULT, 2, 0);

myhtml_tree_t* tree = myhtml_tree_create();
myhtml_tree_init(tree, myhtml);

myhtml_parse(tree, MyENCODING_UTF_8, data, strlen(data));

myhtml_collection_t *classname_list = myhtml_get_nodes_by_attribute_value(tree, NULL, NULL, false, "class", strlen("class"), "name", strlen("name"), NULL);

for (size_t i = 0 ; i < classname_list->length; i++) {
    myhtml_collection_t *text = myhtml_get_nodes_by_tag_id_in_scope(tree, NULL, classname_list->list[i], MyHTML_TAG__TEXT, NULL);

    for (size_t j = 0 ; j < text->length; j++) {
        const char *t = myhtml_node_text(text->list[j], NULL);
        printf("%s\n", t);
    }

    myhtml_collection_destroy(text);
}

myhtml_collection_destroy(classname_list);

myhtml_tree_destroy(tree);
myhtml_destroy(myhtml);

the result is 《经济学聽聽微观部分》, but my need data is 《经济学  微观部分》.
how to solve it?

@lexborisov
Copy link
Owner

I do not understand, in your example there is no 《经济学聽聽微观部分》 data.
I run your example and get result: 《经济学 微观部分》

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