-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (65 loc) · 2.54 KB
/
Program.cs
File metadata and controls
71 lines (65 loc) · 2.54 KB
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using NDesk.Options;
using OpenQA.Selenium.Chrome;
namespace GitScraping
{
class Program
{
static void Main(string[] args)
{
string username = "", password = "", query = "", fileName = "";
bool show_help = false;
var p = new OptionSet() {
{ "u|username=", "{USERNAME} of your github account.",
v => username = v},
{ "p|password=", "{PASSWORD} of your github account.",
v => password = v},
{ "q|query=", "github {QUERY} to scrap.",
v => query = v},
{ "f|file=", "{FILE} name in the query. Scraped data is stored in this file.",
v => fileName = v},
{ "h|help", "show this message and exit",
v => show_help = v != null }
};
List<string> extra;
try {
extra = p.Parse (args);
}
catch (OptionException e) {
Console.Write ("GitScraping: ");
Console.WriteLine (e.Message);
Console.WriteLine ("Try `GitScraping --help' for more information.");
return;
}
if (show_help ||
string.IsNullOrEmpty(username) ||
string.IsNullOrEmpty(password) ||
string.IsNullOrEmpty(query) ||
string.IsNullOrEmpty(fileName))
{
ShowHelp(p);
return;
}
var browserDriverPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
using(var driver = new ChromeDriver(browserDriverPath)){
var scraper = new Scraper(driver, query, fileName, username, password);
scraper.Login();
scraper.GetLinksToCrawl();
scraper.ScrapeLinks();
scraper.Dispose();
}
}
private static void ShowHelp(OptionSet p)
{
Console.WriteLine("Usage: GitScraping [PARAMETERS]");
Console.WriteLine("Scrape credentials on publicly available git repos.");
Console.WriteLine("All 4 parameters are required.");
Console.WriteLine();
Console.WriteLine("Parameters:");
p.WriteOptionDescriptions(Console.Out);
}
}
}