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 虚拟卡⚡️FB BM不限额,短id账单户
BINOM TRACKER 60% OFF!比Adplexity还好用的Spy工具ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理
虚拟信用卡+独立站收款全球虚拟卡, 支持U充值各种主页、账单户、BM户(优势)⚡️TikTok企业户,bm户,账单户
IPCola原生住宅IP⚡️$1.8/条双ISP提供TK企业新户老户、谷歌新户老户海外CL企业户源头PTM虚拟卡[全新卡BIN+高返点]
FB虚拟卡⚡️消费越多返现越多最大欧洲Nutra网盟BA找量 FB个号1块一个寻找顶级电商?AdsBranded等你!
TK老户/国内外端口/预审/加白SX.ORG 高质量代理⚡235+ 地区GG,FB,TK, 欧美源头, 欢迎合作广告位出租
8500万高质量住宅IP,助力各种需求虚拟卡返佣1%,国内持牌机构  
查看: 9753|回复: 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 抓取全站链接
    % H2 \3 s: U% D+ w
  2.         public static List<string> GetAllHref(string url)6 \6 b  }& e- |: Q
  3.         {
    3 C( n5 l1 g- K; P2 B+ F  O: P
  4.             List<string> allHref = new List<string>();
    ! N+ b7 O4 k1 F8 D$ A/ \) B/ R. g2 W
  5.             try
    / _( m( U; ~! c4 @& X! q
  6.             {" x6 C+ `9 v" L* Y5 ]
  7.                 string strhtml = soso.getHtml(url, "", true);) h, E; J9 M/ h  F/ l( B1 l; z( h9 h
  8.                 if (strhtml != "error")3 `( b2 q+ Q5 ?3 [
  9.                 {
    ( u6 U* D7 `! m# y0 [
  10.                     Regex reg = new Regex(@"(?is)<a[^>]*?href=(['""]?)(?<url>[^'""\s>]+)\1[^>]*>(?<text>(?:(?!</?a\b).)*)</a>");  e& _  `2 P+ U" r" w1 a6 Y
  11.                     MatchCollection mc = reg.Matches(strhtml);
    $ D' Q0 i/ n+ w; c
  12.                     foreach (Match m in mc)' D. I: Q" o  D( p
  13.                     {9 {: D  I3 [* @, e
  14.                         Uri uri = new Uri(url);
    / f. o3 r, p1 Z5 k4 g$ n/ X' s) {% c& U
  15.                         Uri thisUri = new Uri(uri, m.Groups["url"].Value);+ H5 ~8 E. ^( g( S
  16.                         string fullUrl = "";
    9 a7 {. ^9 o  e- X8 V, W. v- L
  17.                         if (m.Groups["url"].Value.StartsWith("http"))
    ; B; [; w. ?" w& Q* T
  18.                         {
    3 T8 s/ J: @$ s+ I
  19.                             fullUrl = m.Groups["url"].Value;% h: ^2 F) i9 M5 S( M& i
  20.                         }
    : a# x0 v- Z$ A4 R) V% h
  21.                         else* q, E$ t* e  f# T
  22.                         {
    1 |4 ~1 I  o9 b" q$ ~% a
  23.                             fullUrl = thisUri.ToString();5 S% g, {3 \& N/ l0 e  Q5 L9 v
  24.                         }
    " H9 C5 B5 X& m2 v/ h& l1 t0 o4 P& N
  25.                         allHref.Add(fullUrl);- ]. \: w. ?+ }3 r
  26.                         //Console.WriteLine("原链接:" + m.Groups["url"].Value);
    6 g1 Q" R7 E8 E3 q' v+ w3 l
  27.                         //Console.WriteLine("文本标记:" + m.Groups["text"].Value);, K! L) V  Q6 C6 w+ C2 z; [
  28.                         //Console.WriteLine("补全链接:" + fullUrl);  S  Z5 U) @5 i  E, \' L
  29.                         //Console.WriteLine("…………………………………………");* \( @  l9 ?( Y9 X
  30.                     }, D* f  B8 L) Y
  31.                 }3 L" J- O9 ~8 l8 }5 I2 ^; q
  32.             }. |' S# B5 F: h% F& x' i7 `6 g
  33.             catch (Exception ex)
    9 a% t" A1 C% V; s
  34.             { }7 |) s3 f( x% L* _
  35.             return allHref;6 x) C$ V1 ^2 h- {' }* y: N  x: z
  36.         }" b1 Q7 T6 j0 a7 r4 z9 w. {
  37.         #endregion
复制代码

1 U/ o% V. L. d  d* [( m. ?* L0 M; @5 l" J$ ~% \* |9 R& ~

  1. $ U) E6 ^5 |: r$ D  ^( ]; e% Y
  2. ( V, {. F" {. `0 O. m

  3. % R' P2 g0 n; k# q
  4. #region 数据去重
    # I' X. D3 C9 {& F$ D1 q% _: @
  5.         /// <summary>
    - b" i3 o6 n) K8 f1 J9 H9 L% k
  6.         /// List<string>去重
    . `& S+ b! [5 r0 A, k, f
  7.         /// </summary>4 K% B  X; Z: l  H/ B2 v
  8.         /// <param name="list"></param>+ h& W* C/ l1 o& M5 W
  9.         /// <returns></returns>' H0 E+ v0 R; Z5 L2 B  j
  10.         public static List<string> getUnqueList(List<string> list)" i# a  v2 e6 I+ X
  11.         {/ H8 o: E/ p! {- A
  12.             List<string> list1 = new List<string>();& O) C( `0 y9 I0 B( Y1 @* K" I  X" l5 B. n
  13.             Hashtable hash = new Hashtable();
    0 @7 _* Q/ O9 q# N1 [1 `
  14.             foreach (string s in list). x6 l, s1 l% `7 Q& V: l
  15.             {8 m9 A. n6 u; z' d$ m
  16.                 if (!hash.ContainsKey(s))
    ) E1 }0 S- _9 k9 C( y
  17.                 {
    ; M, X* J) b0 q& @
  18.                     hash.Add(s, s);( U& k; X% b! V/ ~$ V5 ^) ^7 O1 {. C
  19.                     list1.Add(s);
    , W* t: H3 ^  l1 N# [1 `7 [/ k, C
  20.                 }
    9 Z/ s' I% \( d& k0 k
  21.             }
    0 D$ _2 t' Y  P2 l0 T2 `; v6 W! N
  22.             hash.Clear();4 I/ Q+ {1 z* |8 a9 F- k% X: ?. U
  23.             hash = null;- [$ U* y: K* w7 y
  24.             return list1;% ^" T- @6 t/ \9 i: m
  25.         }6 U+ p2 }$ v6 ^. R2 B) Y7 b+ `/ G
  26.         #endregion
复制代码
. |9 g8 Z- [# V3 `7 `/ b
+ E# ]# F7 ^' V

点评

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

使用道具 举报

36

主题

210

广告币

294

积分

初级会员

Rank: 2

积分
294
 楼主| 发表于 2016-2-26 16:20:16 | 显示全部楼层

* y6 U, x/ s: b十分感谢!!!非常感谢!!

点评

缺少一个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
: ]6 O" r7 D" {7 ]2 h6 O# \$ w十分感谢!!!非常感谢!!
6 R' P7 S( _& e) r  q
缺少一个gethtml,用下面这个:
5 L% |! ~$ M# H; U
  1.      public string getHtml(string url, string charSet, bool UseUTF8CharSet)//url是要访问的网站地址,charSet是目标网页的编码,如果传入的是null或者"",那就自动分析网页的编码   f) G/ V; f7 V" ^
  2.         {
    6 r4 h! T* [* x
  3.             string strWebData = "error";9 z6 B9 F$ `+ C
  4.             try
    1 L' @  m+ U% y1 w  ]' o- O; R; P
  5.             {
    " Y" m& d6 |1 Y! f/ W6 E
  6.                 WebClient myWebClient = new WebClient(); //创建WebClient实例myWebClient
    + F$ i& `5 m2 O6 [6 N
  7.                 // 需要注意的:
    - u5 |: }. z: R0 U9 l
  8.                 //有的网页可能下不下来,有种种原因比如需要cookie,编码问题等等
    8 g8 ]. u- v5 O
  9.                 //这是就要具体问题具体分析比如在头部加入cookie 1 \* H' P1 n/ y& r% w
  10.                 // webclient.Headers.Add("Cookie", cookie); & `5 t& m+ y" }, P1 n
  11.                 //这样可能需要一些重载方法。根据需要写就可以了
    $ r1 i) a, F' N/ g! D# O( e
  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)");- F# L" z" n+ N1 U# X* l! B  [
  13.                 //myWebClient.Headers.Add("User-agent", "Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)");9 m1 F6 r# |$ d. j: D" u2 Z5 ]& D
  14.                 //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。 & d! N: l- b5 l0 x! Y
  15.                 myWebClient.Credentials = CredentialCache.DefaultCredentials;( |; r+ S3 K' H8 w
  16.                 //如果服务器要验证用户名,密码
    + O/ _, m2 e4 N7 h& r0 ]' k" g  T
  17.                 //NetworkCredential mycred = new NetworkCredential(struser, strpassword); 4 h# d- [- F( B, |$ J) ~! Q
  18.                 //myWebClient.Credentials = mycred; # b3 q3 M/ O& Z1 ^5 Z% D. V; P
  19.                 //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号) 6 q9 H6 L5 N9 b
  20.                 byte[] myDataBuffer = myWebClient.DownloadData(url);2 |! V4 Q# ^1 e
  21.                 strWebData = Encoding.Default.GetString(myDataBuffer);3 k) X% Y# S! d) ~

  22. - B( |$ Z- Q0 S2 b) y
  23.                 //获取网页字符编码描述信息 % H: k# M: Y4 ?- J
  24.                 Match charSetMatch = Regex.Match(strWebData, "<meta([^<]*)charset=([^<]*)"", RegexOptions.IgnoreCase | RegexOptions.Multiline);
    5 O$ R5 C3 E3 }
  25.                 string webCharSet = charSetMatch.Groups[2].Value;9 q) Y) ~& D7 E' _
  26.                 if (charSet == null || charSet == "")' h7 L% `: T$ |/ @/ n
  27.                     charSet = webCharSet;
    7 l+ [& u9 @. T
  28.                 if (charSet.Length > 0)
    ) E, x  l" G" G  d* L3 ]
  29.                 {% w; J9 r/ i( ?9 `9 m* l) Z
  30.                     charSet = charSet.Replace(""", "");, P/ ?+ T; E' H
  31.                 }9 _9 S, {0 X7 m
  32.                 if (UseUTF8CharSet)
    2 |5 s( _8 |7 ^' a) w7 V
  33.                 {
    ( `5 ~3 l  k  i
  34.                     if (charSet == null || charSet.Length == 0)
    " K& q5 S# k( `1 I: z7 C& }
  35.                     {
    6 U5 Y$ |$ P2 j" }/ T" r
  36.                         charSet = "utf-8";
    * M: e- a3 j8 V( u( d
  37.                     }
    9 P/ j, ~: ~' b, l' @) v! N, j
  38.                 }
    1 i. T3 x6 B1 A7 B7 s0 I  ]# a) N
  39.                 if (charSet != null && charSet != "" && Encoding.GetEncoding(charSet) != Encoding.Default); E6 m/ c1 _! P: _+ ^1 Y
  40.                     strWebData = Encoding.GetEncoding(charSet).GetString(myDataBuffer);
    & e: W0 T& W; ]

  41. % C' N% s  d. a
  42.             }( t6 x/ V, X) |4 C- r9 p
  43.             catch (Exception)# K! _! L7 A8 H, A
  44.             {
    0 T! v  }' \$ L7 t
  45.                 strWebData = "error";
    # y% l' s! W+ K) e3 a1 e. _' D
  46.             }
    : O; n  J9 `9 }2 m7 k6 A( _

  47. $ t: m, Z* x( K4 R7 s) B4 k
  48.             return strWebData;9 y. M& n9 D9 a
  49.         }
复制代码

; R3 I! J3 F  E) n2 C) j
+ m! l" x5 m) W  d( P
回复 支持 反对

使用道具 举报

0

主题

0

广告币

13

积分

新手上路

Rank: 1

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

使用道具 举报

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

本版积分规则

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

GMT+8, 2026-2-15 18:58 , Processed in 0.051309 second(s), 16 queries , Gzip On, MemCache On.

Copyright © 2001-2023, AdvertCN

Proudly Operating in Hong Kong.

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