❶ 怎麼讀取html文件的內容
讀取html文件的內容方法如下:
1、找到.HTML文件的位置;
❷ c語言提取html標簽內容
#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 the target string to str_out
count=0;
for(i=index_begin;i<=index_end;i++)
{
str_out[count]=str_in[i];
count++;
}
str_out[count]='\0';
return;
}
❸ c++如何讀取HTML文件源代碼
這要用到MFC類庫
1.添加頭文件 #include <afxinet.h>
2.添加代碼
CString strAddress="http://www..com";
CInternetSession mySession(NULL,0);
CHttpFile* myHttpFile=NULL;
CString strsource,strline;
myHttpFile=(CHttpFile*)mySession.OpenURL(strAddress);
while(myHttpFile->ReadString(strline))
{
strsource+=strline;
strsource+="\r\n";
}
myHttpFile->Close();
mySession.Close();
strsource存儲的就是html源代碼。
❹ 如何用C語言實現解析HTML文檔
參考下面代碼:
#include <stdio.h>
#include <streamhtmlparser/htmlparser.h>
int main(void)
{
unsigned int getchar_ret;
htmlparser_ctx *parser = htmlparser_new();
while ((getchar_ret = getchar()) != EOF) {
char c = (char)getchar_ret;
/* If we received a '$' character, we output the current tag and attribute
* * name to stdout. */
if (c == '$') {
printf("[[ ");
if (htmlparser_tag(parser)) printf("tag=%s ", htmlparser_tag(parser));
if (htmlparser_attr(parser)) printf("attr=%s ", htmlparser_attr(parser));
printf("]]");
/* If we read any other character, we pass it to the parser and echo it to
* * stdout. */
} else {
htmlparser_parse_chr(parser, c);
putchar(c);
}
}
}
❺ c語言獲取html文件問題
這個b0e是十六進制數,是後面正文的長度,是圖片還是其它文件,在傳輸協議頭中會指明文件類型,要解讀這些東西,必須熟悉http傳輸協議。
❻ 如何運用C語言讀取任意一個html
1. 首先定義一個File 的變數
2.然後用
FILE *fopen(
const char *filename,
const char *mode
);
這個函數讀入 html 文件
3.用這個讀入文件內容
size_t fread(
void *buffer,
size_t size,
size_t count,
FILE *stream
);
4.之後進行字元數組的處理
❼ 怎麼用html打開C語言 ,,並且能夠在html中運行C語言的代碼
C語言是程序語言的鼻祖。不過要想在html中運行c?這我就不理解了。你到底要干什麼?
我們可以把c的exe文件跟html文件打包,從而執行c。也可以用Js把c源碼直接拿出來,展示在瀏覽器上。至於要讓c語言在網頁中發揮作用嗎?也不是不行,沒有c語言做不到的事情。但是就沒有那個必要了。
方法嗎?很白痴,就是用c語言控制瀏覽器進程。通過注射來改變進程的值,以達到改變用戶端的code資料。
或許你想讓html能內嵌一個c語言程序。這個意思也就是內嵌一個exe進程在html中。這不就和上面的想法一樣了嗎?用木馬的辦法綁起來就可以了。
順便說一句,c語言功能雖然強大。其他任何語言能做到的,他都能做到。不過,在某些特定的領域中,不宜用。因為麻煩。例如,你要改變一個值,你用js和用c。那個更容易定位一個變數呢?js和html的關系畢竟就是親,他們之間的調用也方便許多。js也能直接訪問code資料。基本html中的功能使用js都能實現,何必再用c?
如果真的有些問題,必須要用c來解決,還望提出一起討論。
❽ c語言提取html中的信息
1. 如果你懂編程序:
使用字元串匹配演算法,例如KMP演算法,AC演算法等。
AC演算法比較好,網路上可能有現成的,弄一個源代碼,再修改下就可以。
2. 如果你不懂編程:
用word,ultraedit等編輯工具,直接搜索你要的字元串就可以了吧。