aboutsummaryrefslogtreecommitdiff
path: root/tests/main.c
blob: 5b697a9ef10c64b11904d71c3c3a9a42708f687d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
#include "../include/quickmedia/HtmlSearch.h"
#include <assert.h>
#include <stdlib.h>

static char* get_file_content(const char *filepath) {
    FILE *file = fopen(filepath, "rb");
    assert(file);

    fseek(file, 0, SEEK_END);
    size_t filesize = ftell(file);
    fseek(file, 0, SEEK_SET);

    char *buffer = malloc(filesize + 1);
    buffer[filesize] = '\0';
    fread(buffer, 1, filesize, file);

    return buffer;
}

static void result_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, node value: %.*s\n", href, text.size, text.data);
}

int main(int argc, char **argv) {
    char *file_content = get_file_content("test_files/test.html");
    int result = quickmedia_html_find_nodes_xpath(file_content, "//h3[class=\"story_name\"]//a", result_callback, NULL);
    free(file_content);
    return result;
}