C语言的HTML解析器 Streaming HTML parser

jopen 13年前
     <p>Streaming HTML parser 是一个 C 语言的 HTML 解析器。</p>    <p>示例代码:</p>    <pre class="brush:cpp; toolbar: true; auto-links: false;">#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);     }   } }</pre>    <p></p>    <p></p>    <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1324371654843" target="_blank">http://www.open-open.com/lib/view/home/1324371654843</a></p>