C語言的HTML解析器 Streaming HTML parser
Streaming HTML parser 是一個 C 語言的 HTML 解析器。
示例代碼:
#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); } } }
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!