/************************************************************** 功能:从 src 中分析出网页链接,并加入到当前节点的子节点上 ***************************************************************/ void GetLink(char * src) { char * pa, * pb, * pc; char * myanchor = 0; int len = 0; pa = src; do { if((pb = strstr(pa, "href='"))) { pc = strchr(pb + 6, '\''); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href=\""))) { pc = strchr(pb + 6, '"'); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href="))) { GetAfterPosWithSlash(pb + 5, &pc); len = strlen(pb + 5) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 5, len); } else {goto __returnLink ;} if(strlen(myanchor) > 0) AddChildNode(NodeCurr, myanchor); if(pc + 1) pa = pc + 1; }while(pa); __returnLink: return; }
/************************************************************** 功能:从 src 中分析出网页链接,并加入到当前节点的子节点上 ***************************************************************/ void GetLink(char * src) { char * pa, * pb, * pc; char * myanchor = 0; int len = 0; pa = src; do { if((pb = strstr(pa, "href='"))) { pc = strchr(pb + 6, '\''); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href=\""))) { pc = strchr(pb + 6, '"'); len = strlen(pb + 6) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 6, len); } else if((pb = strstr(pa, "href="))) { GetAfterPosWithSlash(pb + 5, &pc); len = strlen(pb + 5) - strlen(pc); GetMemory(&myanchor, len); memcpy(myanchor, pb + 5, len); } else {goto __returnLink ;} /* if(DEBUG) { if(strcmp(NodeCurr->dir, "/")) fprintf(stdout, "%s\thttp://%s/%s/%s\n", myanchor, NodeCurr->host, NodeCurr->dir, strcmp(NodeCurr->page, "`")?NodeCurr->page:""); else fprintf(stdout, "%s\thttp://%s%s%s\n", myanchor, NodeCurr->host, NodeCurr->dir, strcmp(NodeCurr->page, "`")?NodeCurr->page:""); } */ if(strlen(myanchor) > 0) AddChildNode(NodeCurr, myanchor); if(pc + 1) pa = pc + 1; }while(pa); __returnLink: return; }