国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 青州市| 尚义县| 江都市| 崇州市| 阿巴嘎旗| 罗源县| 锦屏县| 呈贡县| 邳州市| 大安市| 富裕县| 岳普湖县| 祁阳县| 石台县| 来宾市| 体育| 卓尼县| 阳新县| 罗定市| 札达县| 松江区| 维西| 漳浦县| 达拉特旗| 西乌珠穆沁旗| 武强县| 光泽县| 佛教| 宣化县| 金溪县| 沧源| 新竹县| 清涧县| 连江县| 九寨沟县| 莱阳市| 兴隆县| 精河县| 哈密市| 大石桥市| 石渠县|