分享

html链接提取/c++

 闲来看看 2011-10-21

html链接提取/c++

bool fetchHref(const char * html)
{
const char *p=html;
const char *p1=NULL;
const char *p2="m";
const char *aneedle="<a";
const char *mneedle="<map";
const char *hneedle="href";
const char *start=0;
int len;
char href[BUFSIZ];
int count=0;
if(!p||!*p) return true;
while(*p){
   p1=strstr(p,aneedle);
   if(p2) p2=strstr(p,mneedle); //一般没有 可以在此提高效率
   if(!p2&&p1) p=p1;   //顺序 效率
   else if(!p1&&!p2) return true;
   else if(!p1&&p2) p=p2;
   else p=p1>p2?p2:p1;
   p=strstr(p,hneedle);
   if(!p) return true;
   while(*p&&*p!='='&&*p!='>') p++;   //find '='
   if(*p++=='='){
   while (*p&&(*p==' '||*p=='\"'||*p=='\'')) p++; //find start  
   if(*p&&*p!='>'){
     start=p;
     len=0;
     while (*p&&*p!=' '&&*p!='\"'&&*p!='\''&&*p!='>'){p++; len++;} //find end
     if(*p){
      memset(href,0,BUFSIZ);
      strncpy(href,start,len);
      printf("%dhref=%s\n",++count,href);
      fs<<href<<endl;
     }
    }
   }
}
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多