AdvertCN - 广告中国

 找回密码
 立即注册

QQ登录

只需一步,快速开始

PropellerAds
Google-Bing-Mediago-Criteo开户
⚡️按条S5代理⚡️静态⚡️独享⚡️5G广告专用虚拟卡/U充值/高返点皇家代理IP⚡️#1性价比⚡️
Mediabuy⚡️玩家开户首选【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️
Taboola/Outbrain /Bing⚡️一级代理开户投流-7*24h❤️人工在线【官方】❤️搜索套利买量投流开户独立站⚡️开户投放
⚡️AdsPower:安全不封号,高效自动化Google FB TK游戏代投⚡️E.PN 虚拟卡⚡️BINOM TRACKER 60% OFF!
比Adplexity还好用的Spy工具ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款
全球虚拟卡, 支持U充值各种主页、账单户、BM户(优势)⚡️TikTok企业户,bm户,账单户IPCola原生住宅IP⚡️$1.8/条双ISP
FB海外户、GG老户、TK加白老户PTM虚拟卡[全新卡BIN+高返点]FB虚拟卡⚡️消费越多返现越多最大欧洲Nutra网盟BA找量
高品质·稳定高速纯净IP FB个号1块一个TikTok2审户/老户/国内外端口/加白SX.ORG 高质量代理⚡235+ 地区
GG,FB,TK, 欧美源头, 欢迎合作❤️跨境债务催收/风险代理高权重Google老户[卖户+筛户等级] 海外斗篷・智能广告过审率高达 99%
DataImpulse⚡️纯净住宅代理仅 $1广告位出租8500万高质量住宅IP,助力各种需求虚拟卡返佣1%,国内持牌机构
查看: 9919|回复: 7

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

[复制链接]

36

主题

210

广告币

294

积分

初级会员

Rank: 2

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

使用道具 举报

2

主题

1475

广告币

1818

积分

高级会员

Rank: 4

积分
1818

社区QQ达人

发表于 2016-2-26 16:17:11 | 显示全部楼层
  1. #region 抓取全站链接
    3 g, i  d; ^2 w' {3 |) e& H6 m
  2.         public static List<string> GetAllHref(string url)
    5 y: C3 c/ A# s3 }
  3.         {6 h7 d8 ]5 Z" {' y! b
  4.             List<string> allHref = new List<string>();
    ; C  b/ d* [1 ~7 U0 `
  5.             try
    5 f/ t7 S/ q. o( n/ b
  6.             {0 m5 L% _. k  z- ^7 H. o: _4 T/ v5 @
  7.                 string strhtml = soso.getHtml(url, "", true);
    % L6 }9 o* b2 L" g( C
  8.                 if (strhtml != "error")2 B; O/ j' v- |6 O. y8 I2 ]
  9.                 {
    4 M* Z0 c  m( X  g( a/ Z) _( |
  10.                     Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");
    " y! u% D( ?. H7 u0 F) p
  11.                     MatchCollection mc = reg.Matches(strhtml);7 T4 A, B* y9 p+ }
  12.                     foreach (Match m in mc)- y* i/ m7 n* G+ m: t* ]2 V
  13.                     {( J$ X% Q7 w9 V5 r
  14.                         Uri uri = new Uri(url);
    5 U7 g  A: N9 m  P+ I+ {
  15.                         Uri thisUri = new Uri(uri, m.Groups["url"].Value);& C5 R% E* x* z( o: K
  16.                         string fullUrl = "";
    ! v; H/ w+ k5 |' [% P
  17.                         if (m.Groups["url"].Value.StartsWith("http"))
      }# q% W; f) [1 ~5 g" E
  18.                         {
    ( C) L+ y7 W4 K" L  {
  19.                             fullUrl = m.Groups["url"].Value;" F* L8 b& p; C" F1 D
  20.                         }! h* S$ a# {0 ^% }; U% J1 O
  21.                         else
    8 E4 A7 y" m" `7 ^9 @1 o, d- K
  22.                         {
    $ B8 k0 s. w# A  \
  23.                             fullUrl = thisUri.ToString();
    * U/ ~, @- }( `6 x- R3 o
  24.                         }
    + J$ S5 X5 [, w& B; i
  25.                         allHref.Add(fullUrl);) S9 i' z9 i, R+ I2 s3 ]( B1 |" J
  26.                         //Console.WriteLine("原链接:" + m.Groups["url"].Value);2 z% }6 H+ @& Q' C2 I: w8 T- I
  27.                         //Console.WriteLine("文本标记:" + m.Groups["text"].Value);
    ! ^" z+ g/ G8 S
  28.                         //Console.WriteLine("补全链接:" + fullUrl);
    + W8 M1 A; G* k( n9 F6 S
  29.                         //Console.WriteLine("…………………………………………");
    2 i8 D, q  _1 {; }! C9 u' `
  30.                     }
    . E& m# X& D; A, s* F
  31.                 }; |5 B. l6 z2 A2 b% D2 u, w* `
  32.             }
    9 \. l/ p0 D; J! w
  33.             catch (Exception ex)
    ; U+ Q+ ?* u# P! r' ]0 m
  34.             { }
    4 {( m1 v" y+ g9 b
  35.             return allHref;% l+ Y+ M) B1 K$ U" e& y
  36.         }
    ) b# \' }6 o0 E: f' D1 d' t
  37.         #endregion
复制代码
1 \" y* |2 {& r" [
7 e, }  N6 N* f. |

  1. + B* K( b) V; V% i4 M! a+ c' y0 G
  2. % x) w7 d; ?8 o2 T
  3. 1 `6 i! @% t+ [/ A. {; g
  4. #region 数据去重
    6 e5 _- t$ `2 Y3 F" V4 R
  5.         /// <summary>
    & O, v5 V0 \1 D0 V: R, J% F4 v) Y
  6.         /// List<string>去重
    $ ^# G+ e' k  e/ ?( D- u2 {
  7.         /// </summary>
    0 j, ~7 c0 T6 a1 f. }3 ?# J: I
  8.         /// <param name="list"></param>* Z1 a/ N( J" @8 `! N% R! D2 T
  9.         /// <returns></returns>
    6 Z9 M" b( \) T/ D# F
  10.         public static List<string> getUnqueList(List<string> list)2 S7 j2 ~4 R+ O$ j, F/ n. i7 L
  11.         {" ~2 J! `9 D6 S1 `
  12.             List<string> list1 = new List<string>();' O! ^9 W8 V0 E) L6 A& e
  13.             Hashtable hash = new Hashtable();
      ]! n. X+ j5 Y+ }6 |. |3 a
  14.             foreach (string s in list)
    & n7 p$ s4 j# a9 y: y- T
  15.             {
    8 h: k% F4 E$ V; b
  16.                 if (!hash.ContainsKey(s))" E# J$ g. w( _/ B6 v9 ?% i- X3 A
  17.                 {2 s* H; [5 X: v+ e6 u5 w- H0 y
  18.                     hash.Add(s, s);
    $ u" Z9 c% y4 l6 x" G5 o
  19.                     list1.Add(s);
    8 R9 W+ r( \1 r: T6 q
  20.                 }0 C+ V2 |, T7 b$ p* ]/ e+ Q) V
  21.             }
    3 A4 E, s9 S* ]( b
  22.             hash.Clear();
    : O0 d6 n1 O, l! p+ i
  23.             hash = null;1 A+ }" x5 v" o3 d* \6 g. O! U
  24.             return list1;
    & ^+ E( U' z, p0 N, a  e
  25.         }
    6 n- M' f8 T- T" i) T+ \
  26.         #endregion
复制代码

0 w$ A1 \" H, E0 C! v# k' C" r7 X

点评

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

使用道具 举报

36

主题

210

广告币

294

积分

初级会员

Rank: 2

积分
294
 楼主| 发表于 2016-2-26 16:20:16 | 显示全部楼层
8 w! D& a  [% F( `! x( I! S2 P- J' }
十分感谢!!!非常感谢!!

点评

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

使用道具 举报

2

主题

1475

广告币

1818

积分

高级会员

Rank: 4

积分
1818

社区QQ达人

发表于 2016-2-26 16:23:12 | 显示全部楼层
guys 发表于 2016-2-26 16:20  s4 P7 \" a# X; H4 }
十分感谢!!!非常感谢!!

2 L3 F; B* f, a6 s! C0 u5 H/ s缺少一个gethtml,用下面这个:
' w7 _' E3 j3 e: v9 Z) {
  1.      public string getHtml(string url, string charSet, bool UseUTF8CharSet)//url是要访问的网站地址,charSet是目标网页的编码,如果传入的是null或者"",那就自动分析网页的编码 4 C8 K, c/ J$ c
  2.         {
    & _* [. ^8 d9 @8 b, x
  3.             string strWebData = "error";3 g& \) U( K7 N. n, ~4 q2 |0 W
  4.             try0 x+ n- M! X4 B6 P3 U, R' t
  5.             {
    7 d/ ^' v. ^1 t* W5 m2 Y
  6.                 WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient " E# n7 w5 \9 `4 x/ u( v6 Y& i
  7.                 // 需要注意的:
    8 H7 N* R* H9 n; C7 M. D4 f
  8.                 //有的网页可能下不下来,有种种原因比如需要cookie,编码问题等等 3 `% y* o' F, k4 B1 m( F- k' k4 b
  9.                 //这是就要具体问题具体分析比如在头部加入cookie
    5 B( j! ?3 t) g! x- c, l: M
  10.                 // webclient.Headers.Add("Cookie", cookie);
    ; K9 f0 R/ T9 b% s* A6 }2 d
  11.                 //这样可能需要一些重载方法。根据需要写就可以了
    % K& x1 D7 f- R5 |& L8 q$ r
  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)");, ]4 E6 ?2 B: n0 Y& Y8 B
  13.                 //myWebClient.Headers.Add("User-agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)");" d  I' C6 j- L' I7 i9 l8 k
  14.                 //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。 ; p2 ]) Y/ K- d  N
  15.                 myWebClient.Credentials = CredentialCache.DefaultCredentials;& o, S& _7 u- m1 N/ ?
  16.                 //如果服务器要验证用户名,密码 * T  [! l8 [& z& c
  17.                 //NetworkCredential mycred = new NetworkCredential(struser, strpassword);
    ) ]+ N" s$ x( L  w4 C) I- j. H
  18.                 //myWebClient.Credentials = mycred; 3 f+ `: ^4 t2 h5 \6 b2 ]; y
  19.                 //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
    5 L) m) K) H, n" @; [
  20.                 byte[] myDataBuffer = myWebClient.DownloadData(url);
    8 y% a" B! A% ^  [) _+ [
  21.                 strWebData = Encoding.Default.GetString(myDataBuffer);* J3 _" d0 e1 u, X' e1 u
  22. 7 }. H& D0 r) j0 h2 P- Y% A
  23.                 //获取网页字符编码描述信息 : T+ M9 |& z7 g3 F, L9 z7 `- \
  24.                 Match charSetMatch = Regex.Match(strWebData, "<meta([^<]*)charset=([^<]*)"", RegexOptions.IgnoreCase | RegexOptions.Multiline);
    $ j  g8 p% v+ F
  25.                 string webCharSet = charSetMatch.Groups[2].Value;  O+ Q( s/ V, j( y. P0 v2 V& L
  26.                 if (charSet == null || charSet == "")8 r7 X2 F4 ]2 p' ~2 ?; [6 |
  27.                     charSet = webCharSet;- {' J9 Z2 W9 y' p7 U  _$ A  c
  28.                 if (charSet.Length > 0)
    % \* Y. G! ~+ T9 C7 V: R. o
  29.                 {) l4 i+ ]6 P. A6 O; w
  30.                     charSet = charSet.Replace(""", "");. X- Z3 W6 C4 x! i" W
  31.                 }
      V' l5 f* G! N$ R* t
  32.                 if (UseUTF8CharSet)2 u( v  ]% w" ~+ f' _
  33.                 {
    : |+ `: X" H! k! s* Q- f; \5 u
  34.                     if (charSet == null || charSet.Length == 0)6 F1 T- h) z/ g! g' W+ m
  35.                     {
    8 P% F7 Y- y; |9 m3 ~! b; L
  36.                         charSet = "utf-8";
    : t' d2 ?0 Z5 N+ s* |: b
  37.                     }
    " d% Y+ K' ]+ ]
  38.                 }
    " b3 w8 i# z% P
  39.                 if (charSet != null && charSet != "" && Encoding.GetEncoding(charSet) != Encoding.Default)# G5 ~, P  g/ ]# N! f) I
  40.                     strWebData = Encoding.GetEncoding(charSet).GetString(myDataBuffer);. I6 z* c. f: Q/ ]/ Q
  41. , f" u& k# v) `9 a) q% R- M
  42.             }! G8 E& X+ o6 }8 W$ |) `
  43.             catch (Exception)! [+ D6 n: y) Z, ~" G
  44.             {: \2 M. y, X' W3 h/ f
  45.                 strWebData = "error";# U9 N, r1 @( s3 ~9 U2 o2 H
  46.             }. A6 V4 |1 e9 O

  47. 5 K: x$ Q1 j# _/ m, U  k
  48.             return strWebData;
    1 h7 b  W/ S% D& g7 E5 R7 U
  49.         }
复制代码

# V  n  m9 c0 f  M
( \$ u5 M6 E4 g; @8 ?0 d
回复 支持 反对

使用道具 举报

0

主题

0

广告币

13

积分

新手上路

Rank: 1

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-3-30 23:12 , Processed in 0.059971 second(s), 20 queries , Gzip On, MemCache On.

Copyright © 2001-2023, AdvertCN

Proudly Operating in Hong Kong.

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