国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#獲取遠程網頁中的所有鏈接URL(網絡蜘蛛實現原理)

2024-07-21 02:25:55
字體:
來源:轉載
供稿:網友

本文介紹網絡蜘蛛獲取網頁中所有鏈接的方法,實現原理:使用system.net.webclient類獲取遠程網頁內容,然后使用url正則表達式分析html代碼中的鏈接。代碼如下:

using system;
using system.net;
using system.text;
using system.text.regularexpressions;

namespace httpget
{
class class1
{
[stathread]
static void main(string[] args)
{
system.net.webclient client = new webclient();
byte[] page = client.downloaddata("http://news.163.com");
string content = system.text.encoding.utf8.getstring(page);
string regex = "href=[///"http:///'](http://////|//.///|///)?//w+(//.//w+)*(/////w+(//.//w+)?)*(///|//?//w*=//w*(&//w*=//w*)*)?[///"http:///']";
regex re = new regex(regex);
matchcollection matches = re.matches(content);

system.collections.ienumerator enu = matches.getenumerator();
while (enu.movenext() && enu.current != null)
{
match match = (match)(enu.current);
console.write(match.value + "/r/n");
}
}
}
}

,歡迎訪問網頁設計愛好者web開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 磴口县| 宣化县| 军事| 桑植县| 琼中| 荥阳市| 藁城市| 黄陵县| 策勒县| 蓝山县| 突泉县| 信宜市| 信阳市| 福泉市| 宁河县| 景东| 定南县| 高州市| 池州市| 东丽区| 托里县| 庆城县| 青铜峡市| 色达县| 晴隆县| 胶州市| 娄烦县| 汨罗市| 大埔县| 弥勒县| 西丰县| 贵州省| 来宾市| 汉中市| 凤冈县| 芜湖市| 班玛县| 樟树市| 三原县| 南京市| 兴安县|