请教:
通过html格式获得了CString类型的html_text,然后怎么可以得到其中的链接<a href……>,还有邮件地址,能不能一个字母一个字母的比较?(如果不用正则表达式)。

解决方案 »

  1.   

    就是蜘蛛的问题。在vc6.0中的,
    如果可以,哪位热心人
    帮忙写个简单的函数
     void getmail()
     {
     CString html_text="this is a test,[email protected],thank you.".
     然后对它操作,获得邮件地址。(不用精确获得邮件地址)。
     }
     或void getlink()
     {
     CString html_text="<body topmargin="0"> <a href="bbsmail.php" ppppppppppp>";
     然后对它操作,获得href链接的地址。
     }
    很感谢。
    p.s:如果不用正则表达式。
      

  2.   

    呵呵 没做过这种东西,最笨的方法就象楼主说的遍历了。 
    判断单词 如果等于herf,取得后边""内部的东西(html里格式应该都比较规范的吧?)
    电子邮件地址类似吧,遇到字符@,进行判断@前后单词,@前的第一个单词是用户名,@后边的是第一个非.标志的单词结束符前的所有字符为邮件服务器地址。有漏洞,楼主仔细想想还有什么好方法 。
    提供个单词遍历demo。参考!
    =============================
    #include "stdio.h"
    #include "fstream.h"
    #include "string.h"
    #include "ctype.h"struct WORD
    {
        char w[30];
    WORD *next;
    };int CompareWord(WORD *,char []);
    void SaveResult(int,int,int);void main()
    {
    char Current[30]={""},letter;
    WORD *word,*pS,*pEnd;
    pS=new WORD;
    word=NULL;
    int m,n=0,i,j,k,LineNum=0,WordNum=0,TheNum=0;

    fstream myFile("Text.txt",ios::out|ios::in);
    if(myFile.fail())
    {
    cerr<<"error opening file!\n";
    return;
    }
    cout<<"The content of the file is:"<<endl<<endl;
    letter=myFile.get();
    while (!myFile.eof())
    {
    cout.put(letter);//输出内容
    letter=toupper(letter);//字母大写
    m=int(letter);
    //遇到 字母、数字、' 以及连接符-  算单词内容 
    //将读取的一个单词放入一个临时数组
    if((m>=65&&m<=90)||(m>=48&&m<=57)||(m==96))
    {
    Current[n]=letter;
    n++;
    }
    // m=int(letter);
    //统计行数
    if(m==10)
    LineNum++;
    //非单词内容 开始计数 单词个数
    if(!((m>=65&&m<=90)||(m>=48&&m<=57)||(m==96)||(m==45)))
    {
    //统计the 的数目
    Current[n]='\0';
    if(strcmp(Current,"THE")==0)
    TheNum++;
    //统计单词数
    if(Current[0]!='\0')
    {
    //比较单词   将不同的存入word 链表中
    j=CompareWord(word,Current);
    if(j!=0)
    {
    WordNum++;
    for(i=0;i<=n;i++)
    pS->w[i]=Current[i];
    if(word==NULL)
    word=pS;
    else
    pEnd->next=pS;
    pEnd=pS;
    pS=new WORD;
    }
    }
    Current[0]='\0';//临时数组清空
    n=0;
    }
    pS->next=NULL;
    letter=myFile.get();
    }
    delete pS;
    //遇到文件结尾行数加一
    if(myFile.eof())
    LineNum++;
    cout<<endl<<"The mumber of line is:"<<LineNum<<endl<<"The number of words is:"<<WordNum<<endl
    <<"The number of 'the'is :"<<TheNum<<endl;

    SaveResult(LineNum,WordNum,TheNum);
    }int CompareWord(WORD *s,char c[30])
    {
    int q=1;
    while(s!=NULL)
    {
    q=strcmp(s->w,c);
    if(q==0)
    break;
    s=s->next;
    }
    return q;
    }
    void SaveResult(int lnum,int wnum,int tnum)
    {
    cout<<"You also can see the result in the file---'Result.txt'!!"<<endl;

    fstream In("Result.txt",ios::in|ios::out);

    In<<"The number of the lines in the file you opened is:"<<lnum<<'\n';
    In<<"The words in the file is:"<<wnum<<'\n';
    In<<"The number of 'the' is :"<<tnum<<'\n';

    }
      

  3.   

    一个从网页tag里面分析url和url标题的类http://www.vckbase.com/document/viewdoc/?id=1196