c语言提取html中的信息

html-css010

c语言提取html中的信息,第1张

1. 如果你懂编程序:

使用字符串匹配算法,例如KMP算法,AC算法等。

AC算法比较好,网络上可能有现成的,弄一个源代码,再修改下就可以。

2. 如果你不懂编程:

用word,ultraedit等编辑工具,直接搜索你要的字符串就可以了吧。

string strLine

using (System.IO.StreamReader sr = new System.IO.StreamReader("C:\text.html"))

{

strLine = sr.ReadLine()

}

System.Console.WriteLine(strLine)

可以这样写

#include <stdio.h>

#include <math.h>

void fetch_str(char *str_in, char *str_out)

int main(){

char test[] = "<a>This is the <...>string</a>"

char result[256]

fetch_str(test, result)

printf("\ntest\t=%s\n", test)

printf("\nresult\t=%s\n",result)

return 1

}

void fetch_str(char *str_in, char *str_out)

{

char begin_str[] = "<a>"

char end_str[] = "</a>"

int index_end =0

int index_begin=0

int flag_begin =0

int flag_end =0

int str_index=0

int i

// to find the max index of str_in

while(str_in[str_index]!='\0')

{

str_index++

}

str_index--

//printf("%s %s", begin_str, end_str)

int count=0

while(str_in[count]!='\0')

{

// to find the begin index of the target string

if( flag_begin==0 &&count<=(str_index-2) )

{

if( str_in[count]==begin_str[0] &&str_in[count+1]==begin_str[1] &&str_in[count+2]==begin_str[2] )

{

flag_begin=1

index_begin=count+3

}

}

// to find the end index of the target string

//if( flag_end==0 &&count<=(str_index-3) )

if(count<=(str_index-3) )

{

if( str_in[count]==end_str[0] &&str_in[count+1]==end_str[1] &&str_in[count+2]==end_str[2] &&str_in[count+3]==end_str[3])

{

flag_end=1

index_end=count-1

}

}

count++

}

//printf("\nbegin_index=%d, end_index=%d\n", index_begin, index_end)

// to copy the target string to str_out

count=0

for(i=index_begini<=index_endi++)

{

str_out[count]=str_in[i]

count++

}

str_out[count]='\0'

return

}