streamhtmlparserライブラリ(Web解析の簡単なテスト)
次の操作を実行するには、streamhtmlparserソースライブラリを先に実行する必要があります.
一、
htmlparser.c
二、
実行後に次のデータを入力
三、
出力データ
一、
htmlparser.c
#include <stdio.h> #include <streamhtmlparser/htmlparser.h> int main(void) { unsigned int getchar_ret; htmlparser_ctx *parser = htmlparser_new(); while((getchar_ret = getchar()) != EOF) { char c = (char)getchar_ret; /* If we received a '$' character, we output the current tag and attribute * name to stdout. */ if (c == '$') { printf("[[ "); if (htmlparser_tag(parser)) printf("tag=%s ", htmlparser_tag(parser)); if (htmlparser_attr(parser)) printf("attr=%s ", htmlparser_attr(parser)); printf("]]"); /* If we read any other character, we pass it to the parser and echo it to * stdout. */ } else { htmlparser_parse_chr(parser, c); putchar(c); } } }
二、
実行後に次のデータを入力
<html> <body $> <title> $ </title> <a href="$" alt="$"> url </a> </body> </html>
三、
出力データ
<html> <body [[ tag=body ]]> <title> [[ tag=title ]] </title> <a href="[[ tag=a attr=href ]]" alt="[[ tag=a attr=alt ]]"> url </a> </body> </html>