C 獲取網頁內容,並且處理正確編碼

2022-05-03 18:51:10 字數 1672 閱讀 2479

控制台呼叫

static void main(string args)

下面的**不重要,只是可以獲取標題或其它內容

//

獲取網頁的html內容,根據網頁的charset自動判斷encoding

static

string gethtml(string

url)

//獲取網頁的html內容,指定encoding

static

string gethtmls(string

url, encoding encoding)

//根據網頁的html內容提取網頁的encoding

static encoding getencoding(string

html)

catch (argumentexception)

}//根據網頁的html內容提取網頁的title

static

string gettitle(string

html)

//列印網頁的encoding和title

static

void printencodingandtitle(string

url)

] ", getencoding(html), gettitle(html));

}

裡面的**不重要,只是獲取其它的內容

///

///獲取源**

/// ///

///public

static

string gethtml(string

url, encoding encoding)

}catch

finally

if (reader != null

) reader.close();

if (request != null

) request = null

; }

return

string

.empty;

}public

static

string getencodings(string

url)

//else if (response.characterset != string.empty)

//

//else

//return encoding.default.bodyname;

////xmldocument xml = new xmldocument();

// }

return

null

;

}catch

finally

if (reader != null

) reader.close();

if (request != null

) request = null

; }

}

這裡才是真正的**,這裡乙個是獲取正確的編碼,乙個是根據編碼解析原始碼

c 獲取網頁內容

http s34.pet.mop.com petwin.html title 檢視 nclick p.showpetinfo 0,機警小雞 49597282678812,false,false,false,true p.setfuji 0 return false 機警小雞 r nhttp s34....

VC獲取網頁內容

下面是codeguru上的乙個使用wininet類的例子,它能夠從給定的url位址中 獲取該檔案。這個例子實現了兩個方法 cstring getwebpage const cstring url void seterrormessage cstring s getwebpage是主要的方法,後面跟的...

php 獲取網頁內容

方法1 用file get contents 以get方式獲取內容 url html file get contents url echo html 方法2 用file get contents函式,以post方式獲取url 如果需要再傳遞cookie資料,則把 content length str...