C 之獲取網頁標題

2022-08-16 13:18:20 字數 601 閱讀 4145

效果截圖如下:

主要**如下:

//獲取網頁標題函式

private string getwebtitle(string url)

catch(exception e)

//從流中讀出資料

streamreader sr=new streamreader(webstream, system.text.encoding.default);

//建立可變字元物件,用於儲存網頁資料

stringbuilder sb = new stringbuilder();

//讀出資料存入可變字元中

string str = "";

while ((str=sr.readline())!=null)

//建立獲取網頁標題正規表示式

string regex = @".+";

//返回網頁標題

string title=regex.match(sb.tostring(),regex).tostring();

title=regex.replace(title,@"[\""]+","");

return title;

}

如何獲取和修改HTML網頁標題

作為乙個標準的html文件,網頁標題 title 是必不可少的屬性。隨著瀏覽器的發展,我們又多了一種訪問和修改文件的方式 dom。所以我們獲取網頁標題的方式大致可分為以下兩種 通過document物件訪問title vartitle document.title 通過dom方式訪問title var...

php網頁示例,php獲取網頁標題的三種方法示例

一 curl方法 推薦 複製 示例 c curl init url www.jbxue.com curl setopt c,curlopt url,url curl setopt c,curlopt returntransfer,1 data curl exec c curl close c pos...

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....