找回密码
 立即注册

QQ登录

只需一步,快速开始

PropellerAds
Google-Bing-Mediago-Criteo开户
⚡️按条S5代理⚡️静态⚡️独享⚡️5G广告专用虚拟卡/U充值/高返点皇家代理IP⚡️#1性价比⚡️
Mediabuy⚡️玩家开户首选【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️
Taboola/Outbrain /Bing⚡️一级代理开户投流-7*24h❤️人工在线【官方】❤️搜索套利买量投流开户独立站⚡️开户投放
Google FB TK游戏代投⚡️E.PN 虚拟卡⚡️BINOM TRACKER 60% OFF!比Adplexity还好用的Spy工具
ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款全球虚拟卡, 支持U充值
Facebook 批量上广告尤里改 - FB 稳定投放免费黑五教程(持续更新、欢迎交流)FB 三不限源头 - 自助下户充值转款
各种主页、账单户、BM户(优势)IPCola原生住宅IP⚡️$1.8/条双ISPFB资源,账单户,分享户,国内一手TK加白户/二解户/FB海外户/GG老户
海外CL企业户源头最大欧洲Nutra网盟BA找量 FB高权重耐操个号⚡️稳定过审GG,FB,TK, 欧美源头, 欢迎合作❤️
FB企业户海外户,授信户,TK加白户联盟收款/海外资金下发/服贸结汇⚡️Spend.net — 美元卡仅需$0⚡️比特浏览器+云手机 |防关联防封号
Facebook截流, 1 次点击 2 次曝光✔Taboola海外户广告位出租8500万高质量住宅IP,助力各种需求
虚拟卡返佣1%,国内持牌机构   
查看: 10180|回复: 7

[业界] 求推荐一个一键提取网站里面的URL且根据域名去重复的小...

[复制链接]

36

主题

213

广告币

297

积分

初级会员

积分
297
发表于 2016-2-26 16:08:04 | 显示全部楼层 |阅读模式
回复

使用道具 举报

2

主题

1486

广告币

1828

积分

高级会员

积分
1828

社区QQ达人

发表于 2016-2-26 16:17:11 | 显示全部楼层
  1. #region 抓取全站链接% t% {# [) |& }, r! K
  2.         public static List<string> GetAllHref(string url)( B! q' A1 c0 g4 s1 N
  3.         {
    7 r6 }5 |2 h) F( [+ b
  4.             List<string> allHref = new List<string>();
    7 |/ |7 \3 ?/ k1 p4 c
  5.             try' H( ^7 r$ U1 V. e4 j' I3 n9 H
  6.             {) a! c" c+ d  h# n
  7.                 string strhtml = soso.getHtml(url, "", true);2 G' _1 m. Z$ C- @( Z! C) S
  8.                 if (strhtml != "error")
    ' Q# @7 w# f! u; ^/ k6 W4 m5 e6 R
  9.                 {
    & L) m7 H, O5 I) l) a2 y
  10.                     Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");) G6 q3 `+ Q. O
  11.                     MatchCollection mc = reg.Matches(strhtml);' F  s. N/ z; f+ }
  12.                     foreach (Match m in mc)
    4 n" W+ x  u, n4 w6 A1 T
  13.                     {
    ( Z6 K7 O# w0 ~) M
  14.                         Uri uri = new Uri(url);$ K3 P/ F7 q( o
  15.                         Uri thisUri = new Uri(uri, m.Groups["url"].Value);. w! w9 b3 {- ~7 {/ _: \
  16.                         string fullUrl = "";! }# _. J3 d/ q8 A
  17.                         if (m.Groups["url"].Value.StartsWith("http"))
    : \# i+ |6 V/ _2 P
  18.                         {
    7 i5 g# I, n  w& k: f+ q9 G
  19.                             fullUrl = m.Groups["url"].Value;& E- V* t/ z3 ?7 O+ B; @3 X
  20.                         }: x5 U! o2 B. U% U" K# g3 B' J
  21.                         else
    7 ?+ m  C( p% N" \/ A
  22.                         {) {1 ~' a6 B( `% F1 E* X
  23.                             fullUrl = thisUri.ToString();
    9 {. S/ J0 O2 V" _
  24.                         }# M7 B0 y6 O/ O; D8 }/ ]9 m
  25.                         allHref.Add(fullUrl);
    9 j3 K8 m# }' y% P1 a. Z/ k$ q
  26.                         //Console.WriteLine("原链接:" + m.Groups["url"].Value);& s% ?& t% E" {! m  Q
  27.                         //Console.WriteLine("文本标记:" + m.Groups["text"].Value);; @8 ~! L+ }2 {8 W" b6 o
  28.                         //Console.WriteLine("补全链接:" + fullUrl);% Z# o) j6 q$ J7 \
  29.                         //Console.WriteLine("…………………………………………");
    3 V2 I* p* Z5 L/ C! T7 \
  30.                     }
    + X7 i; v8 N+ w$ Q6 p% l2 \
  31.                 }2 ^  o* S  W4 \8 j8 z
  32.             }
    & P* ?1 i% `! e/ L( ^6 p, m- i& \7 q
  33.             catch (Exception ex)
    ; H6 G4 ^$ n" |  V6 |/ W* y7 u
  34.             { }3 O( L7 r- x/ |6 f5 F) i; ?
  35.             return allHref;; i" |. B' O% G7 ~  e. {- ~* K8 D
  36.         }
    ) p' u* _6 P5 s8 O6 E& J! D
  37.         #endregion
复制代码
1 m- V; F! m  c& N" a

2 n( c: r6 f8 r, y; z2 z# {6 m, J

  1. # E9 W3 [$ g* m. F0 @! j9 [

  2. ! J8 \% h& U5 w( S* p0 J

  3. # P: `: q/ b2 V2 \8 e
  4. #region 数据去重/ y! f' m" T4 {8 ?4 T" x
  5.         /// <summary>3 R. h6 w* T- }
  6.         /// List<string>去重; r/ O2 D9 {. Q" Z; C( P" j# B
  7.         /// </summary>+ I4 K& P% q0 t: u
  8.         /// <param name="list"></param>. d% `, w7 \% A3 j; I/ c% L8 [
  9.         /// <returns></returns>
    % i, Z0 V$ Y) l% _
  10.         public static List<string> getUnqueList(List<string> list)
    ' R5 N/ W% u" k9 v; T5 O, i7 N5 R
  11.         {" X7 G4 Q5 b, I- Y" B* u) O
  12.             List<string> list1 = new List<string>();$ F3 f( H5 E7 H
  13.             Hashtable hash = new Hashtable();7 N7 [7 t/ z; n
  14.             foreach (string s in list)! H  j4 |! s% v
  15.             {
    : a( y1 M# A. C' U" h( u& v
  16.                 if (!hash.ContainsKey(s))
    4 _3 Y1 l$ F# h, b: l
  17.                 {
    + [" o0 \3 G5 ?- g: P2 Y. n' N
  18.                     hash.Add(s, s);
    5 P" c3 K1 d9 t5 K; D  P8 U- m
  19.                     list1.Add(s);; O7 T! N& Y, n1 ?
  20.                 }( G% ^! L. \6 I% h( }& P) l
  21.             }
    % f2 x  d) V5 F8 V& C4 Z' ?9 [
  22.             hash.Clear();
    2 M, x  N. p1 l
  23.             hash = null;" Q' Z- @8 v& x9 v' W
  24.             return list1;: m  C8 g! ?; n$ F/ Y% `, t+ R6 B' {
  25.         }7 ]' I. _9 G; w6 h8 ?
  26.         #endregion
复制代码
6 m" R, Z/ s0 V! d

/ K; N4 r( _- x0 |

点评

谢谢分享  发表于 2016-2-27 15:15
十分感谢!!!非常感谢!!  详情 回复 发表于 2016-2-26 16:20
回复 支持 反对

使用道具 举报

36

主题

213

广告币

297

积分

初级会员

积分
297
 楼主| 发表于 2016-2-26 16:20:16 | 显示全部楼层
5 @' A5 r1 D6 x, y1 T& J
十分感谢!!!非常感谢!!

点评

缺少一个gethtml,用下面这个:  详情 回复 发表于 2016-2-26 16:23
回复 支持 反对

使用道具 举报

2

主题

1486

广告币

1828

积分

高级会员

积分
1828

社区QQ达人

发表于 2016-2-26 16:23:12 | 显示全部楼层
guys 发表于 2016-2-26 16:20
/ U7 i) n2 `1 Z5 l十分感谢!!!非常感谢!!
/ s5 J: P% `7 d; [1 S
缺少一个gethtml,用下面这个:" ^- G8 @: _- W8 I/ k5 B# Q
  1.      public string getHtml(string url, string charSet, bool UseUTF8CharSet)//url是要访问的网站地址,charSet是目标网页的编码,如果传入的是null或者"",那就自动分析网页的编码 5 T- [0 i; Q; c1 c& ?& L
  2.         {# A3 |: ?# J+ v' N7 e
  3.             string strWebData = "error";
    : [- ]. Q1 M7 `1 y
  4.             try# w! J) u5 Q& E& }
  5.             {) A/ \' \: U' B  z
  6.                 WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient ! O  N3 ^* l# y" @5 E3 z0 K0 I
  7.                 // 需要注意的: 0 |) l4 q1 }# u  d: n
  8.                 //有的网页可能下不下来,有种种原因比如需要cookie,编码问题等等
    + q$ H. P; u+ t) y: c  `9 M6 A
  9.                 //这是就要具体问题具体分析比如在头部加入cookie
    5 c! L3 @  [7 V; J. k6 }
  10.                 // webclient.Headers.Add("Cookie", cookie); - |3 H5 _2 r$ G  V5 K
  11.                 //这样可能需要一些重载方法。根据需要写就可以了: R- ?( D1 C# F8 l8 W+ N1 h( N" ~
  12.                 myWebClient.Headers.Add("User-agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)");! F5 D" O& g) B7 J4 K
  13.                 //myWebClient.Headers.Add("User-agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)");
    3 T) o9 O% E$ A" r$ L  d) }) e- @
  14.                 //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。
    % j- J* [3 G7 U9 p/ y1 @
  15.                 myWebClient.Credentials = CredentialCache.DefaultCredentials;. h5 h- I, l9 |9 K$ j3 }! b
  16.                 //如果服务器要验证用户名,密码 4 W1 ?4 y8 P# v6 k) U) W) G# s
  17.                 //NetworkCredential mycred = new NetworkCredential(struser, strpassword); & X2 s3 v! R+ R7 R$ ?
  18.                 //myWebClient.Credentials = mycred;
    9 _7 ~& M1 c5 ^
  19.                 //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号) 3 e) A' d5 _$ v2 w& i: T6 h. f& e& }
  20.                 byte[] myDataBuffer = myWebClient.DownloadData(url);# P1 T" M7 R3 v5 \/ v
  21.                 strWebData = Encoding.Default.GetString(myDataBuffer);! g* |: }+ t, Z0 C. H
  22. # a; G0 u" R. q) q4 O. J1 G8 G
  23.                 //获取网页字符编码描述信息
    $ }  [2 L8 j+ G# Q
  24.                 Match charSetMatch = Regex.Match(strWebData, "<meta([^<]*)charset=([^<]*)"", RegexOptions.IgnoreCase | RegexOptions.Multiline);( H( m$ p. I  Z  P1 `
  25.                 string webCharSet = charSetMatch.Groups[2].Value;) o7 o) f  A2 l
  26.                 if (charSet == null || charSet == "")
    - l$ X3 t6 S; M! ]6 v( b) c
  27.                     charSet = webCharSet;
    ; @. x/ h5 H' ^6 e) I9 U/ }( ?
  28.                 if (charSet.Length > 0)  q- Q  V9 F; e
  29.                 {' `( C4 x5 ~7 w8 k* r$ h; Y$ F
  30.                     charSet = charSet.Replace(""", "");3 w: @  ~7 ^& Z( i. s1 [
  31.                 }6 V7 s# n+ Z' O
  32.                 if (UseUTF8CharSet)5 g" |# w* ]1 u' v" I
  33.                 {
    0 n1 s5 o6 H( B1 `) l* j7 `  H
  34.                     if (charSet == null || charSet.Length == 0)
    & n+ Y" {/ Y+ Q
  35.                     {* Y* m* s5 `/ e9 s5 h9 M* l
  36.                         charSet = "utf-8";0 E- Q& b4 a  J
  37.                     }
    7 ^$ D* L0 R1 }: q4 e( E, z  ?8 P
  38.                 }
    & x' R& [$ R& z% ~  A
  39.                 if (charSet != null && charSet != "" && Encoding.GetEncoding(charSet) != Encoding.Default); e: ]3 w4 f0 O5 T2 D0 k7 Q) n9 G
  40.                     strWebData = Encoding.GetEncoding(charSet).GetString(myDataBuffer);& \) N# F- K0 s+ c- l
  41. % G3 Y' \" k3 T; L5 d4 d' E  a9 W
  42.             }- q- W- Y  ]; c4 R5 ^+ E
  43.             catch (Exception)
    3 L9 F; f. s( L. U& y* N
  44.             {3 b0 F8 |7 A* c/ |6 Y- s9 C" a
  45.                 strWebData = "error";) M6 o3 @0 V9 F3 F6 ^/ l: G. \- @
  46.             }
      b6 {) n: i- T# i4 \
  47. " N* W- j" T% N0 G6 w7 Y- x
  48.             return strWebData;8 U9 w3 d- e1 E& x
  49.         }
复制代码

' K; r  D4 q) y: A0 W. S$ G1 s$ u& s4 Y8 ?, A
回复 支持 反对

使用道具 举报

0

主题

0

广告币

13

积分

新手上路

积分
13
发表于 2016-2-26 19:05:59 | 显示全部楼层
weishaneweishane
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们|联系我们|DMCA|广告服务|小黑屋|手机版|Archiver|Github|网站地图|AdvertCN

GMT+8, 2026-8-2 01:50 , Processed in 0.089942 second(s), 27 queries , Gzip On.

Copyright © 2001-2026, AdvertCN

Proudly Operating in Hong Kong.

快速回复 返回顶部 返回列表