根據當前頁面url匹配出頁面內鏈結位址的完整路徑

2022-04-12 08:42:05 字數 1723 閱讀 5366

該類其功能相當於瀏覽器對當前頁面內鏈結位址的解析功能

主要方法是 字串的操作,正規表示式的匹配和替換。

比如所當前頁為:其頁面內鏈結為:

baseurl

result

/default.aspx?id=14

../details.aspx?id=4

dete.aspx

該類c#**:

using system;

using system;

using system.collections;

using system.collections.generic;

using system.text;

using system.text.regularexpressions;

public class utility

else

//開頭不是 "../"

if (branchurl.indexof("../") != 0)

else

else if (regex.match(baseurl, @"/[^\./]+\.[^/]+$", regexoptions.compiled).success)

while (branchurl.indexof("../") >= 0)

return baseurl + "/" + branchurl;}}

}/// /// branchurl相對路徑為根目錄 "/test.aspx"

///

/// 當前頁面位址

/// 頁面內鏈結位址 "/test.aspx"

///

private static string getlasturl(string baseurl, string branchurl)

if (end_url.indexof("/") > 0)

if (star_url != string.empty)//協議型別不為空

else

}/// /// branchurl相對路徑包為 單獨頁面 ep "test.aspx"

///

/// 當前頁面位址 ep

/// 頁面內鏈結位址 "test.aspx"

在資料採集的時候,在文章列表頁中匹配出文章內容頁的完整路徑。

JS獲取當前頁面頁面URL資訊

url即 統一資源定位符 uniform resource locator,url 完整的url由這幾個部分構成 scheme host port path?query fragment scheme 通訊協議 常用的http,ftp,maito等 設定或獲取url從頭到埠號部分。url windo...

c 獲取當前頁面URl

2 通過js獲取 thisdloc document.location thisurl document.url thishref document.location.href thissloc self.location.href thistloc top.location.href thispl...

獲取當前頁面的URL

window location host 返回url 的主機部分,例如 www.com window location hostname 返回www.com window location href 返回整個url字串 window location pathname 返回 a index.php或...