热门推荐
正则表达式提取链接地址-邮箱邮件
2024-12-20 21:22
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;

}

    以上就是本篇文章【正则表达式提取链接地址-邮箱邮件】的全部内容了,欢迎阅览 ! 文章地址:http://www78564.xrbh.cn/quote/27361.html 
     动态      相关文章      文章      同类文章      热门文章      栏目首页      网站地图      返回首页 迅博思语移动站 http://www78564.xrbh.cn/mobile/ , 查看更多