diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-05-25 16:52:49 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-05-25 16:55:24 +0200 |
commit | 109c797d7c89223c9eed07dc322448b5c5fe3373 (patch) | |
tree | 20e538d4f5d558832d2984a1d60f810c387e9838 /tests | |
parent | 7cde49baf87b8340c608e76bc6052769deb1cdf4 (diff) |
Convert to sibs, add curl download, write test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/main.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..3ba930b --- /dev/null +++ b/tests/main.c @@ -0,0 +1,45 @@ +#include <stdio.h> +#include "../include/Program.h" +#include <quickmedia/HtmlSearch.h> +#include <stdlib.h> +#include <string.h> + +typedef struct { + char *data; + size_t size; +} Buffer; + +static int program_output_callback(char *data, int size, void *userdata) { + Buffer *buf = userdata; + size_t new_size = buf->size + size; + buf->data = realloc(buf->data, new_size + 1); + buf->data[new_size] = '\0'; + memcpy(buf->data + buf->size, data, size); + buf->size = new_size; + return 0; +} + +static void html_search_callback(QuickMediaHtmlNode *node, void *userdata) { + const char *href = quickmedia_html_node_get_attribute_value(node, "href"); + QuickMediaStringView text = quickmedia_html_node_get_text(node); + printf("a href: %s, text: %.*s\n", href, text.size, text.data); +} + +int main(int argc, char **argv) { + Buffer buf; + buf.data = NULL; + buf.size = 0; + char *args[] = { "/usr/bin/curl", "-s", "-L", "https://manganelo.com/search/naruto", NULL }; + exec_program(args, program_output_callback, &buf); + /*printf("%s\n", buf.data);*/ + + QuickMediaHtmlSearch html_search; + if(quickmedia_html_search_init(&html_search, buf.data) != 0) + return -1; + if(quickmedia_html_find_nodes_xpath(&html_search, "//h3[class=\"story_name\"]//a", html_search_callback, NULL) != 0) + return -1; + quickmedia_html_search_deinit(&html_search); + + free(buf.data); + return 0; +} |