推广 热搜:   公司  中国  行业  快速  设备  企业  上海  未来  2025 

正则表达式提取链接地址-邮箱邮件

   日期:2024-12-20     移动:http://www78564.xrbh.cn/mobile/quote/27361.html
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Web;
using System.IO;
using System.Collections;
using System.Text.Regularexpressions;


namespace chinaz
{
class Program
{
staticvoid Main(string[] args)
{

string cookie =null;
using (StreamReader sr =new StreamReader("cookie.txt"))
{
cookie
= sr.ReadToEnd();
sr.Close();
}
//string tmp = SRWebClient.GetPage("http://bbs.chinaz.com/Members.html?page=1&sort=CreateDate&desc=true&keyword=", Encoding.UTF8, cookie);
int a =int.Parse(Console.ReadLine());
int b =int.Parse(Console.ReadLine());
string url = Console.ReadLine();

Hashtable hash
=new Hashtable();
Encoding encoding
= Encoding.GetEncoding(Console.ReadLine());

for (int i = a; i <= b; i++)
{
string html = SRWebClient.GetPage(string.Format(url, i), encoding, cookie);
//Console.WriteLine(html);
if (html !=null&& html.Length >1000)
{
Match m
= Regex.Match(html, @"/w+([-+.']/w+)*@/w+([-.]/w+)*/https://www.cnblogs.com/szgzwf/archive/2012/11/05/w+([-.]/w+)*", RegexOptions.Compiled | RegexOptions.IgnoreCase);
while (m !=null&& m.Value !=null&& m.Value.Trim() !=string.Empty)
{
if (!hash.Contains(m.Value))
{
Console.WriteLine(m.Value);
using (StreamWriter sw =new StreamWriter("mail.txt", true))
{
sw.WriteLine(m.Value);
sw.Close();
}
hash.Add(m.Value,
string.Empty);
}
m
= m.NextMatch();
}

}
}



Console.Write(
"完成");
Console.ReadLine();
}
}
publicclass SRWebClient

{

public cookieCollection cookie;

public SRWebClient()

{

cookie
=null;

}



#region 从包含多个 cookie 的字符串读取到 cookieCollection 集合中

privatestaticvoid AddcookieWithcookieHead(ref cookieCollection cookieCol, string cookieHead, string defaultDomain)

{

if (cookieCol ==null) cookieCol =new cookieCollection();

if (cookieHead ==null) return;

string[] ary = cookieHead.Split(';');

for (int i =0; i < ary.Length; i++)

{

cookie ck
= GetcookieFromString(ary[i].Trim(), defaultDomain);

if (ck !=null)

{

cookieCol.Add(ck);

}

}

}

#endregion



#region 读取某一个 cookie 字符串到 cookie 变量中

privatestatic cookie GetcookieFromString(string cookieString, string

{

string[] ary = cookieString.Split(',');

Hashtable hs
=new Hashtable();

for (int i =0; i < ary.Length; i++)

{

string s = ary[i].Trim();

int index = s.IndexOf("=");

if (index >0)

{

hs.Add(s.Substring(
0, index), s.Substring(index +1));

}

}

cookie ck
=new cookie();

foreach (object Key in hs.Keys)

{

if (Key.ToString() =="path") ck.Path = hs[Key].ToString();



elseif (Key.ToString() =="expires")

{

//ck.Expires=DateTime.Parse(hs[Key].ToString();

}

elseif (Key.ToString() =="domain") ck.Domain = hs[Key].ToString();

else

{

ck.Name
= Key.ToString();

ck.Value
= hs[Key].ToString();

}

}

if (ck.Name =="") returnnull;

if (ck.Domain =="") ck.Domain = defaultDomain;

return ck;

}

#endregion









///<TgData>

///<Alias>下载Web源代码</Alias>

///</TgData>

publicstring DownloadHtml(string URL, bool Createcookie)

{

try

{

HttpWebRequest request
= HttpWebRequest.Create(URL) as HttpWebRequest;

if (cookie !=null)

{

request.cookieContainer
=new cookieContainer();

request.cookieContainer.Add(cookie);

}

request.AllowAutoRedirect
=false;

//request.MaximumAutomaticRedirections = 3;

request.Timeout =20000;



HttpWebResponse res
= (HttpWebResponse)request.GetResponse();

string r ="";



System.IO.StreamReader S1
=new System.IO.StreamReader(res.GetResponseStream(), System.Text.Encoding.Default);

try

{

r
= S1.ReadToEnd();

if (Createcookie)

cookie
= res.cookies;

}

catch (Exception er)

{

//Log l = new Log();

//l.writelog("下载Web错误", er.ToString());

}

finally

{

res.Close();

S1.Close();

}



return r;

}



catch

{



}



returnstring.Empty;

}


特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


相关最新动态
推荐最新动态
点击排行
网站首页  |  二维码  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  粤ICP备2023022329号