#include "htmlparser_cpp.h"
#include
#include
#include
using namespace std;
using namespace streamhtmlparser;
int main( int argc, char *argv[] )
{
if( argc != 2 ) {
cerr << "Usage: test2 \n" << endl;
return 1;
}
char *htmlFileName = argv[1];
HtmlParser parser;
ifstream htmlFile( htmlFileName );
if( !htmlFile.good( ) ) {
cerr << "ERROR: Can't open file '" << htmlFileName << "'" << endl;
return 1;
}
string link;
char buf[1] = {0};
bool in_link = false;
while( htmlFile.good( ) && !htmlFile.eof( ) ) {
buf[0] = htmlFile.get( );
parser.Parse( buf, 1 );
if( parser.state( ) == HtmlParser::STATE_VALUE && parser.tag( ) != NULL && parser.attribute( ) != NULL && parser.value( ) != NULL ) {
if( strcmp( parser.tag( ), "a" ) == 0 && strcmp( parser.attribute( ), "href" ) == 0 ) {
link = parser.value( );
in_link = true;
}
} else if( in_link && parser.state( ) == HtmlParser::STATE_TAG ) {
cout << link << endl;
link.clear( );
in_link = false;
} else if( parser.state( ) == HtmlParser::STATE_ERROR ) {
cerr << endl << "ERROR at " << endl;
return 1;
}
}
return 0;
}