-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefault.aspx.cs.exclude
411 lines (361 loc) · 18.3 KB
/
Default.aspx.cs.exclude
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.Serialization;
using System.Web.Caching;
using System.Net.Mail;
using System.Threading;
public partial class _Default : Page
{
private List<string> list = new List<string>();
private CVDataClassesDataContext mainDb = new CVDataClassesDataContext();
/// <summary>
/// Get a string representation of a webpage's source.
/// </summary>
/// <param name="URL">The URL to get the source from.</param>
/// <returns></returns>
public string getPageSource(string URL)
{
WebClient webClient = new WebClient();
string strSource = webClient.DownloadString(URL);
webClient.Dispose();
return strSource;
}
public class SearchResult
{
public string url;
public string title;
public string content;
public FindingEngine engine;
public enum FindingEngine { google, bing, google_and_bing };
public SearchResult(string url, string title, string content, FindingEngine engine)
{
this.url = url;
this.title = title;
this.content = content;
this.engine = engine;
}
}
public static List<SearchResult> GoogleSearch(string search_expression,
Dictionary<string, object> stats_dict)
{
var url_template = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=large&safe=active&q={0}&start={1}";
Uri search_url;
var results_list = new List<SearchResult>();
try
{
search_url = new Uri(string.Format(url_template, search_expression, 0));
var page = new WebClient().DownloadString(search_url);
JObject o = (JObject)JsonConvert.DeserializeObject(page);
var t = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 8));
var page1 = new WebClient().DownloadString(search_url);
JObject o2 = (JObject)JsonConvert.DeserializeObject(page);
var t2 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 16));
var page2 = new WebClient().DownloadString(search_url);
JObject o3 = (JObject)JsonConvert.DeserializeObject(page);
var t3 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 24));
var page4 = new WebClient().DownloadString(search_url);
JObject o4 = (JObject)JsonConvert.DeserializeObject(page);
var t4 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 32));
var page5 = new WebClient().DownloadString(search_url);
JObject o5 = (JObject)JsonConvert.DeserializeObject(page);
var t5 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 40));
var page6 = new WebClient().DownloadString(search_url);
JObject o6 = (JObject)JsonConvert.DeserializeObject(page);
var t6 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 48));
var page7 = new WebClient().DownloadString(search_url);
JObject o7 = (JObject)JsonConvert.DeserializeObject(page);
var t7 = o["responseData"]["results"].Children();
search_url = new Uri(string.Format(url_template, search_expression, 56));
var page8 = new WebClient().DownloadString(search_url);
JObject o8 = (JObject)JsonConvert.DeserializeObject(page);
var t8 = o["responseData"]["results"].Children();
var results_query1 = from result in t
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query2 = from result in t2
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query3 = from result in t3
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query4 = from result in t4
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query5 = from result in t5
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query6 = from result in t6
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query7 = from result in t7
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
var results_query8 = from result in t8
select
new SearchResult(
result.Value<string>("url").ToString(),
result.Value<string>("title").ToString(),
result.Value<string>("content").ToString(),
SearchResult.FindingEngine.google
);
foreach (var result in results_query1)
results_list.Add(result);
foreach (var result in results_query2)
results_list.Add(result);
foreach (var result in results_query3)
results_list.Add(result);
foreach (var result in results_query4)
results_list.Add(result);
foreach (var result in results_query5)
results_list.Add(result);
foreach (var result in results_query6)
results_list.Add(result);
foreach (var result in results_query7)
results_list.Add(result);
foreach (var result in results_query8)
results_list.Add(result);
}
catch (Exception e)
{
string m = e.Message;
}
return results_list;
}
protected void runJob_Click(object sender, EventArgs e)
{
//int count = 0;
//int totalCount = mainDb.CVMails.Count();
//List<SearchResult> results = GoogleSearch("", new Dictionary<string, object>());
//StreamWriter writer = new StreamWriter(@"C:\Users\Or\Desktop\CV\Spider\spider.txt", true);
//foreach (SearchResult d in results)
//{
// try
// {
// string g = getPageSource(d.url);
// Regex t = new Regex(@"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
// foreach (Match m in t.Matches(g))
// {
// CVMail f = mainDb.CVMails.SingleOrDefault(b => b.MailValue == m.Value);
// if (f == null)
// {
// mainDb.CVMails.InsertOnSubmit(new CVMail
// {
// MailID = mainDb.CVMails.Count() + 1,
// MailValue = m.Value
// });
// mainDb.SubmitChanges();
// this.list.Add(m.Value);
// writer.Write(m.Value + ", ");
// count++;
// }
// }
// }
// catch (Exception s)
// {
// string ng = s.Message;
// continue;
// }
//}
//this.doneLabel.Text = count.ToString();
//this.totalLabel.Text = totalCount.ToString();
//if (writer != null)
//{
// writer.Close();
//}
int count = 0;
int totalCount = mainDb.CVMails.Count();
List<string> list = new List<string>();
if (!string.IsNullOrEmpty(search1.Text))
{
list.Add(search1.Text);
}
if (!string.IsNullOrEmpty(search2.Text))
{
list.Add(search2.Text);
}
if (!string.IsNullOrEmpty(search3.Text))
{
list.Add(search3.Text);
}
if (!string.IsNullOrEmpty(search4.Text))
{
list.Add(search4.Text);
}
if (!string.IsNullOrEmpty(search5.Text))
{
list.Add(search5.Text);
}
if (!string.IsNullOrEmpty(search6.Text))
{
list.Add(search6.Text);
}
if (!string.IsNullOrEmpty(search7.Text))
{
list.Add(search7.Text);
}
if (!string.IsNullOrEmpty(search8.Text))
{
list.Add(search8.Text);
}
if (!string.IsNullOrEmpty(search9.Text))
{
list.Add(search9.Text);
}
if (!string.IsNullOrEmpty(search10.Text))
{
list.Add(search10.Text);
}
if (!string.IsNullOrEmpty(search11.Text))
{
list.Add(search11.Text);
}
if (!string.IsNullOrEmpty(search12.Text))
{
list.Add(search12.Text);
}
search1.Text = string.Empty;
search2.Text = string.Empty;
search3.Text = string.Empty;
search4.Text = string.Empty;
search5.Text = string.Empty;
search6.Text = string.Empty;
search7.Text = string.Empty;
search8.Text = string.Empty;
search9.Text = string.Empty;
search10.Text = string.Empty;
search11.Text = string.Empty;
search12.Text = string.Empty;
StreamWriter writer = new StreamWriter(@"C:\Users\Or\Desktop\CV\Spider\spider.txt", true);
foreach (string d in list)
{
try
{
string g = getPageSource(d);
Regex t = new Regex(@"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?");
foreach (Match m in t.Matches(g))
{
CVMail f = mainDb.CVMails.SingleOrDefault(b => b.MailValue == m.Value);
if (f == null)
{
mainDb.CVMails.InsertOnSubmit(new CVMail
{
MailID = mainDb.CVMails.Count() + 1,
MailValue = m.Value
});
mainDb.SubmitChanges();
writer.Write(m.Value + ", ");
this.list.Add(m.Value);
// var fromAddress = new MailAddress();
// var toAddress = new MailAddress(m.Value, "To Name");
// const string subject = "";
// const string body = "";
// var smtp = new SmtpClient
// {
// Host = "smtp.gmail.com",
// Port = 587,
// EnableSsl = true,
// DeliveryMethod = SmtpDeliveryMethod.Network,
// UseDefaultCredentials = false,
// Credentials = new NetworkCredential()
// };
// Attachment cv = new Attachment();
// MailMessage mail = new MailMessage(fromAddress, toAddress);
// mail.Attachments.Add(cv);
// mail.Subject = subject;
// mail.Body = body; ;
// smtp.Send(mail);
// Thread.Sleep(5000);
count++;
}
}
}
catch (Exception s)
{
this.doneLabel.Text = s.Message;
break;
}
}
this.doneLabel.Text = count.ToString();
this.totalLabel.Text = totalCount.ToString();
if (writer != null)
{
writer.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<string> list = new List<string>();
StreamReader r = new StreamReader(@"C:\Users\Or\Desktop\CV\Spider\spider.txt");
StringBuilder build = new StringBuilder();
while (!r.EndOfStream)
{
build.Append(r.ReadLine());
}
string[] stringer = build.ToString().Split(',');
foreach (string m in stringer)
{
if (!list.Contains(m))
{
this.list.Add(m);
}
}
//this.doneLabel.Text = "0";
this.totalLabel.Text = stringer.Count().ToString();
r.Close();
}
}
}