-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
190 lines (154 loc) · 7.34 KB
/
Program.cs
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
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System.Configuration;
using SeleniumExtras.WaitHelpers;
namespace WebScreenshot
{
internal class Program
{
public static string dir = GetSetting("dir").ToString() + DateTime.Now.ToString("dd" + " MMMM" + " yyyy");
public static string W = GetSetting("W").ToString();
public static string H = GetSetting("H").ToString();
public static string nama = "";
public static string link = "";
public static string Y;
static void Main(String[] args)
{
Console.Title = "Web Auto Screenshot By Zhafif " + DateTime.UtcNow.ToString() + " UTC+ ";
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Clear();
if (Directory.Exists(dir))
{
Console.WriteLine("Folder Tempat Save Sudah Ada");
}
else
{
DirectoryInfo directory = Directory.CreateDirectory(dir);
Console.WriteLine("Folder Tempat Save Dibuat");
}
Console.WriteLine("Jadi Anda Mau Ngescreenshot Web Apa Hari Ini ?");
Console.WriteLine("");
LOOPING(Y);
Console.WriteLine(Y);
}
private static void LOOPING(string Y)
{
Console.WriteLine("Ketik Y untuk Screenshot Web Costume");
Console.WriteLine("Ketik W untuk Screenshot Web "+GetSetting("judul"));
Console.WriteLine("Ketik N Atau C Atau E untuk Keluar");
Y = Console.ReadLine();
if (Y == "y" || Y == "Y")
{
CaptureCosutmeLink();
}
else if (Y == "w" || Y == "W")
{
CaptureWebPage();
}
else if (Y == "n" || Y == "N" || Y == "c" || Y == "C" || Y == "e" || Y == "E")
{
Environment.Exit(0);
}
else
{
Console.WriteLine("Tolong Ketik Pilihan Yang Tersedia Saja");
LOOPING(Y);
}
}
private static void CaptureCosutmeLink()
{
Console.WriteLine("Anda Ingin Melakukan Screenshot Lainnya ? Silahkan Masukan Nama Filenya");
Console.BackgroundColor = ConsoleColor.DarkBlue;
nama = Console.ReadLine();
Console.WriteLine("Oke Namanya " + nama + ", Baiklah Sekarang Silahkan Kopas Linknya");
link = Console.ReadLine();
Console.WriteLine("Baiklah Tunggu Sebentar Sedang Membuka Websitenya ...");
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-gpu");
options.AddArgument("test-type");
options.AddArgument("start-maximized");
options.AddArgument("--window-size="+ W +"," + H);
options.AddArgument("test-type=browser");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--enable-precise-memory-info");
options.AddArgument("--disable-default-apps");
options.AddArguments("--disable-popup-blocking");
options.AddArgument("--headless");
IWebDriver driver = new ChromeDriver(options);
Console.WriteLine("Sedang Menghidupkan Bot Aplikasinya ...", Console.ForegroundColor = ConsoleColor.Yellow);
Console.WriteLine("Jangan Diclose Sampai Selesai Ya Kalo Mau Beneran Ke Save", Console.ForegroundColor = ConsoleColor.Red);
Console.WriteLine("", Console.ForegroundColor = ConsoleColor.White);
Console.WriteLine("");
Console.WriteLine("Memproses Tampilan Website " + nama, Console.ForegroundColor = ConsoleColor.White);
driver.Navigate().GoToUrl(link);
ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
Thread.Sleep(10000);
wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("img")));
Screenshot screenshot = screenshotDriver.GetScreenshot();
screenshot.SaveAsFile(dir + "\\" + nama + ".png");
Console.WriteLine(nama + " Telah Berhasil di Save");
driver.Close();
LOOPING(Y);
}
private static void CaptureWebPage()
{
ChromeOptions options = new ChromeOptions();
options.AddArgument("--disable-gpu");
options.AddArgument("test-type");
options.AddArgument("start-maximized");
options.AddArgument("--window-size=" + W + "," + H);
options.AddArgument("test-type=browser");
options.AddArgument("--ignore-certificate-errors");
options.AddArgument("--enable-precise-memory-info");
options.AddArgument("--disable-default-apps");
options.AddArguments("--disable-popup-blocking");
options.AddArgument("--headless");
IWebDriver driver = new ChromeDriver(options);
Console.WriteLine("");
Console.WriteLine("Sedang Menghidupkan Bot Aplikasinya ...", Console.ForegroundColor = ConsoleColor.Yellow);
Console.WriteLine("Jangan Diclose Sampai Selesai Ya Kalo Mau Beneran Ke Save", Console.ForegroundColor = ConsoleColor.Red);
Console.WriteLine("", Console.ForegroundColor = ConsoleColor.White);
driver.Navigate().GoToUrl(GetSetting("link0"));
try
{
for (int i = 0; i < int.Parse(GetSetting("jumlah")); i++)
{
Console.WriteLine("");
Console.WriteLine("Sedang Memproses Tampilan Halaman " + GetSetting(i.ToString()), Console.ForegroundColor = ConsoleColor.White);
driver.Navigate().GoToUrl(GetSetting("link" + i.ToString()));
ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(120));
wait.Until(ExpectedConditions.ElementIsVisible(By.TagName("img")));
Thread.Sleep(10000);
Screenshot screenshot = screenshotDriver.GetScreenshot();
screenshot.SaveAsFile(dir + "\\" + GetSetting(i.ToString()) + ".png");
Console.WriteLine(GetSetting(i.ToString()) + " Telah Berhasil di Save");
Console.WriteLine("");
}
}
catch (Exception e)
{
if(e.ToString() == "System.ArgumentNullException: Argument 'url'")
{
Console.WriteLine("");
Console.WriteLine("Screenshot Website "+ GetSetting("judul") + " Berhasil");
driver.Close();
LOOPING(Y);
}
}
Console.WriteLine(GetSetting("Screenshot Website "+ GetSetting("judul") + " Berhasil"));
driver.Close();
LOOPING(Y);
}
private static string GetSetting(string key)
{
return ConfigurationManager.AppSettings[key];
}
private static string GetLinks(string key)
{
return ConfigurationManager.AppSettings.Get(key);
}
}
}