using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenQA.Selenium.Chrome;
public partial class Form1 : Form
this.InitializeComponent();
private void addLog(bool hasTime, string log)
string time = "[" + DateTime.Now.ToString("HH:mm:ss") + "]";
log = time.Trim() + "\t " + log;
this.lb_log.Items.Add(log);
this.lb_log.SelectedItem = log;
string directoryPath = string.Concat(new object[]
bool flag = !Directory.Exists(directoryPath);
Directory.CreateDirectory(directoryPath);
string filePath = string.Concat(new string[]
(DateTime.Now.Hour > 9) ? DateTime.Now.Hour.ToString() : ("0" + DateTime.Now.Hour),
(DateTime.Now.Minute > 9) ? DateTime.Now.Minute.ToString() : ("0" + DateTime.Now.Minute),
(DateTime.Now.Second > 9) ? DateTime.Now.Second.ToString() : ("0" + DateTime.Now.Second),
using (StreamWriter sw = new StreamWriter(filePath))
foreach (object item in this.lb_log.Items)
sw.WriteLine(item.ToString() + "\n");
MessageBox.Show("Can't save log!");
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Process.Start("https://www.bing.com/");
private void button1_Click(object sender, EventArgs e)
this.comboBox1.Enabled = false;
this.button1.Enabled = false;
this.textBox1.Enabled = false;
this.numtimeh.Enabled = false;
this.numtimem.Enabled = false;
this.numtimes.Enabled = false;
this.numtrangview.Enabled = false;
this.numspview.Enabled = false;
this.numtimeclickimg.Enabled = false;
this.numtimeclicksee.Enabled = false;
this.numtimeclickcmt.Enabled = false;
this.linktrangchu = this.comboBox1.SelectedItem.ToString();
this.numtimehko = (int)this.numtimeh.Value;
this.numtimemko = (int)this.numtimem.Value;
this.numtimesko = (int)this.numtimes.Value;
this.listKeysearch.Clear();
string[] tempArray = this.textBox1.Lines;
for (int counter = 0; counter < tempArray.Length; counter++)
bool flag = tempArray[counter].Length == 0;
this.listKeysearch.Add(tempArray[counter]);
bool flag2 = this.listKeysearch.Count == 0;
MessageBox.Show("Chưa Điền Key Search");
this.comboBox1.Enabled = true;
this.button1.Enabled = true;
this.textBox1.Enabled = true;
new Thread(async delegate()
this.lb_log.Items.Clear();
this.addLog(true, "Mở trình duyệt chrome");
ChromeDriverService service = ChromeDriverService.CreateDefaultService();
service.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
string ChromeProfileDirectory = Environment.ExpandEnvironmentVariables("%LocalAppData%") + "\\BraveSoftware\\Brave-Browser\\User Data";
options.AddArgument("user-data-dir=" + ChromeProfileDirectory);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddAdditionalCapability("useAutomationExtension", false);
chromeOptions.AddExcludedArgument("enable-automation");
options.AddArguments(new string[]
"--disable-notifications",
"--disable-dev-shm-usage",
"--disable-web-security",
"--disable-rtc-smoothness-algorithm",
"--disable-webrtc-hw-decoding",
"--disable-webrtc-hw-encoding",
"--disable-webrtc-multiple-routes",
"--disable-webrtc-hw-vp8-encoding",
"--enforce-webrtc-ip-permission-check",
"--force-webrtc-ip-handling-policy",
"--ignore-certificate-errors",
"--disable-popup-blocking",
ChromeDriver driver = new ChromeDriver(service, options);
this.addLog(true, "Mở trang " + this.linktrangchu);
driver.Url = this.linktrangchu;
this.addLog(true, "lỗi mở trang");
this.button1.Enabled = true;
this.comboBox1.Enabled = true;
this.textBox1.Enabled = true;
this.numtimeh.Enabled = true;
this.numtimem.Enabled = true;
this.numtimes.Enabled = true;
this.numtrangview.Enabled = true;
this.numspview.Enabled = true;
this.numtimeclickimg.Enabled = true;
this.numtimeclicksee.Enabled = true;
this.numtimeclickcmt.Enabled = true;
List<string> listsp = new List<string>();
for (int keyss = 0; keyss < this.listKeysearch.Count; keyss = num + 1)
driver.FindElementByXPath("//*[@id=\"sp-cc-accept\"]").Click();
this.addLog(true, "Search Key " + this.listKeysearch[keyss] + ".");
driver.FindElementByXPath("//*[@id=\"twotabsearchtextbox\"]").SendKeys(this.listKeysearch[keyss]);
driver.FindElementByXPath("/html/body/div[1]/header/div/div[1]/div[2]/div/form/div[2]/div[1]/input").SendKeys(this.listKeysearch[keyss]);
driver.FindElementByXPath("//*[@id=\"nav-search-submit-text\"]/input").Click();
driver.FindElementByXPath("/html/body/div[1]/header/div/div[1]/div[2]/div/form/div[3]/div/span/input").Click();
bool flag2 = url != driver.Url;
MatchCollection matchCollection3 = Regex.Matches(driver.PageSource, "href=\"(.*?)\"");
foreach (object obj in matchCollection3)
string str = m3.Groups[1].Value;
bool flag3 = !str.Contains("/dp/");
bool flag4 = str[0] == '/' && str[1] == 'd' && str[2] == 'p' && str[3] == '/';
MatchCollection matchCollection4 = Regex.Matches(str, "(.*?)/ref=");
foreach (object obj2 in matchCollection4)
string str2 = m4.Groups[1].Value;
for (int kttrung = 0; kttrung < listsp.Count; kttrung = num + 1)
bool flag5 = str2.Trim() == listsp[kttrung].Trim();
this.addLog(true, "Lấy thành công links sản phẩm!");
while (spp < listsp.Count)
bool flag7 = spp >= (int)this.numspview.Value;
this.addLog(true, "Load links sản phẩm thứ: " + (spp + 1));
driver.Url = this.linktrangchu + listsp[spp];
this.addLog(true, "lỗi mở trang");
this.button1.Enabled = true;
this.comboBox1.Enabled = true;
this.textBox1.Enabled = true;
this.numtimeh.Enabled = true;
this.numtimem.Enabled = true;
this.numtimes.Enabled = true;
this.numtrangview.Enabled = true;
this.numspview.Enabled = true;
this.numtimeclickimg.Enabled = true;
this.numtimeclicksee.Enabled = true;
this.numtimeclickcmt.Enabled = true;
driver.FindElementByXPath("//*[@id=\"sp-cc-accept\"]").Click();
for (int clickh = 0; clickh < 10; clickh = num + 1)
driver.FindElementByXPath("//*[@id=\"sp-cc-accept\"]").Click();
driver.FindElementByXPath("//*[@id=\"altImages\"]/ul/li[" + clickh + "]").Click();
this.addLog(true, "Click hình thứ: " + stthinh);
for (int choo = (int)this.numtimeclickimg.Value; choo >= 0; choo = num - 1)
this.label2.Text = "Waiting.." + choo + "s";
for (int xt = 0; xt < 20; xt = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt + "\"]/div/header/button/i").Click();
bool flag8 = stthinh == 0;
this.addLog(true, "Không có hình để xem.");
for (int xt2 = 0; xt2 < 20; xt2 = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt2 + "\"]/div/header/button/i").Click();
IWebElement element = driver.FindElementByXPath("//*[@id=\"cr-pagination-footer-0\"]/a");
int y = element.Location.Y;
int a = y / ((int)this.numtimeclicksee.Value * 2);
for (int op = 0; op < (int)this.numtimeclicksee.Value * 2 - 2; op = num + 1)
IJavaScriptExecutor js = driver;
js.ExecuteScript("javascript:window.scrollBy(0, " + a + ")", new object[0]);
for (int xt3 = 0; xt3 < 20; xt3 = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt3 + "\"]/div/header/button/i").Click();
IWebElement element2 = driver.FindElementByXPath("//*[@id=\"reviews-medley-footer\"]/div[2]/a");
int y2 = element2.Location.Y;
int a2 = y2 / ((int)this.numtimeclicksee.Value * 2);
for (int op2 = 0; op2 < (int)this.numtimeclicksee.Value * 2 - 2; op2 = num + 1)
IJavaScriptExecutor js2 = driver;
js2.ExecuteScript("javascript:window.scrollBy(0, " + a2 + ")", new object[0]);
this.addLog(true, "Không có comments");
this.addLog(true, "Click see all comment");
for (int xt4 = 0; xt4 < 20; xt4 = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt4 + "\"]/div/header/button/i").Click();
driver.FindElementByXPath("//*[@id=\"cr-pagination-footer-0\"]/a").Click();
driver.FindElementByXPath("//*[@id=\"reviews-medley-footer\"]/div[2]/a").Click();
bool flag9 = url != driver.Url;
for (int xemcmt = 1; xemcmt <= (int)this.numtrangview.Value; xemcmt = num + 1)
bool flag10 = xemcmt == 1;
bool flag11 = xemcmt2 == 11;
bool flag12 = xemcmt != 1 && xemcmt2 == 1;
IWebElement element3 = driver.FindElementByXPath("//*[@id=\"filterByKeywordTextBox\"]");
toado = element3.Location.Y;
IWebElement element4 = driver.FindElementByXPath("//*[@id=\"cm_cr-review_list\"]/div[" + xemcmt2 + "]");
y3 = element4.Location.Y;
bool flag14 = xemcmt == 1;
this.addLog(true, string.Concat(new object[]
bool flag15 = xemcmt2 != 1;
this.addLog(true, string.Concat(new object[]
int a3 = (y3 - toado) / ((int)this.numtimeclickcmt.Value * 2);
for (int op3 = 0; op3 < (int)this.numtimeclickcmt.Value * 2; op3 = num + 1)
IJavaScriptExecutor js3 = driver;
js3.ExecuteScript("javascript:window.scrollBy(0, " + a3 + ")", new object[0]);
driver.FindElementByXPath(string.Concat(new object[]
"//*[@id=\"cm_cr-review_list\"]/div[",
"]/div/div/div[6]/div[1]/img[",
this.addLog(true, "Click hình thứ " + slhinh + " trong comment!");
for (int choo2 = (int)this.numtimeclickimg.Value; choo2 >= 0; choo2 = num - 1)
this.label2.Text = "Waiting.." + choo2 + "s";
for (int iu = 0; iu < 20; iu = num + 1)
for (int xt5 = 0; xt5 < 10; xt5 = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt5 + "\"]/div/div/div/div/div/div/div[2]/div[2]/div[3]/div").Click();
this.addLog(true, "Click hình thứ " + slhinh + " trong comment!");
for (int choo3 = (int)this.numtimeclickimg.Value; choo3 >= 0; choo3 = num - 1)
this.label2.Text = "Waiting.." + choo3 + "s";
for (int xt6 = 0; xt6 < 20; xt6 = num + 1)
driver.FindElementByXPath("//*[@id=\"a-popover-" + xt6 + "\"]/div/header/button/i").Click();
driver.FindElementByXPath("//*[@id=\"cm_cr-pagination_bar\"]/ul/li[2]/a").Click();
bool flag16 = url != driver.Url;
driver.FindElementByXPath("//*[@id=\"cm_cr-pagination_bar\"]/ul/li[2]/a").Click();
this.addLog(true, "Đã xem xong " + (int)this.numspview.Value + " Sản phẩm.");
this.addLog(true, "Đã search hết keyword.");
this.addLog(true, "Xong");
this.addLog(true, "Start hẹn giờ!");
int tongtime = (int)this.numtimeh.Value * 60 * 60 + (int)this.numtimem.Value * 60 + (int)this.numtimes.Value;
for (int tii = tongtime; tii >= 0; tii = num - 1)
this.numtimeh.Value = tii / 3600;
this.numtimem.Value = tii / 60 % 60;
this.numtimes.Value = tii % 60;
this.numtimeh.Value = this.numtimehko;
this.numtimem.Value = this.numtimemko;
this.numtimes.Value = this.numtimesko;
this.addLog(true, "Lỗi mở trình duyệt");
this.button1.Enabled = true;
this.comboBox1.Enabled = true;
this.textBox1.Enabled = true;
this.numtimeh.Enabled = true;
this.numtimem.Enabled = true;
this.numtimes.Enabled = true;
this.numtrangview.Enabled = true;
this.numspview.Enabled = true;
this.numtimeclickimg.Enabled = true;
this.numtimeclicksee.Enabled = true;
this.numtimeclickcmt.Enabled = true;
private void Form1_Load(object sender, EventArgs e)
this.comboBox1.SelectedItem = "https://www.amazon.com";
this.button1.Enabled = false;
private void button2_Click(object sender, EventArgs e)
this.lb_log.Items.Clear();
this.button1.Enabled = true;
this.comboBox1.Enabled = true;
this.textBox1.Enabled = true;
this.numtimeh.Enabled = true;
this.numtimem.Enabled = true;
this.numtimes.Enabled = true;
this.numtrangview.Enabled = true;
this.numspview.Enabled = true;
this.numtimeclickimg.Enabled = true;
this.numtimeclicksee.Enabled = true;
this.numtimeclickcmt.Enabled = true;
private string linktrangchu = "";
private List<string> listKeysearch = new List<string>();
private int numtimehko = 0;
private int numtimemko = 0;
private int numtimesko = 0;