forked from ebrasha/abdal-web-visitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (60 loc) · 2.42 KB
/
Program.cs
File metadata and controls
69 lines (60 loc) · 2.42 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System.Threading;
using System.Reflection;
class Program
{
static void Main()
{
// Get Software Version and Change Title
var version = Assembly.GetExecutingAssembly().GetName().Version;
Console.Title = "Abdal Web Visitor :: Ver " + version;
Console.WriteLine("");
Console.WriteLine("Programmer: Ebrahim Shafiei (EbraSha)");
Console.WriteLine("Email: Prof.Shafiei@Gmail.com");
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("##################################");
Console.WriteLine("");
// Read settings
var settingsXml = XDocument.Load("settings.xml");
bool infinite = bool.Parse(settingsXml.Root.Element("Infinite").Value);
int loadWaitTime = int.Parse(settingsXml.Root.Element("LoadWaitTime").Value);
bool enableScroll = bool.Parse(settingsXml.Root.Element("EnableScroll").Value);
int scrollWaitTime = int.Parse(settingsXml.Root.Element("ScrollWaitTime").Value);
int idleTimeAfterScroll = int.Parse(settingsXml.Root.Element("IdleTimeAfterScroll").Value);
// Read URLs
var urlsXml = XDocument.Load("urls.xml");
List<string> urls = urlsXml.Root.Elements("url").Select(x => x.Value).ToList();
// Open browser
IWebDriver driver = new ChromeDriver(".");
try
{
do
{
foreach (var url in urls)
{
driver.Navigate().GoToUrl(url);
Thread.Sleep(loadWaitTime);
if (enableScroll)
{
// Scroll to the middle of the page
((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight/2)");
Thread.Sleep(scrollWaitTime);
// Scroll to the end of the page
((IJavaScriptExecutor)driver).ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
Thread.Sleep(idleTimeAfterScroll);
}
}
} while (infinite);
}
finally
{
driver.Quit();
}
}
}