¿Cómo utilizar el lenguaje C para analizar documentos HTML?
Consulte el siguiente código:
#include lt;stdio.hgt;
#include lt;streamhtmlparser/htmlparser.hgt;
int main(void )
{
unsigned int getchar_ret;
htmlparser_ctx *parser = htmlparser_new()
while ((getchar_ret = getchar(); ) ! = EOF) {
char c = (char)getchar_ret;
/* Si recibimos un carácter "$", obtendremos la etiqueta y el atributo actuales
** Nombre de salida a 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("]]");
/* Si leemos algún otro carácter, lo pasamos al analizador y lo devolvemos a
* * stdout. */
} else {
htmlparser_parse_chr(parser, c
putchar(c);
}
}
}
}