-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
42 lines (42 loc) · 1.54 KB
/
Form1.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
using OpenQA.Selenium;
using System;
using System.Collections.ObjectModel;
using System.Windows.Forms;
namespace Selenium
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OpenQA.Selenium.Chrome.ChromeDriver driver;
private void BtnAra_Click(object sender, EventArgs e)
{
try
{
if (!string.IsNullOrWhiteSpace(txtAranacakKelime.Text))
{
driver = new OpenQA.Selenium.Chrome.ChromeDriver();
driver.Navigate().GoToUrl("https://www.google.com/search?q=" + txtAranacakKelime.Text);
//Sonuçları döndür
int toplam = driver.FindElements(By.TagName("cite")).Count;
for (int i = 0; i < toplam; i++)
{
ReadOnlyCollection<IWebElement> Liste = driver.FindElements(By.XPath("//*[@id='rso']/div/div/div[" + i + "]/div/div/div[1]/a[1]"));
foreach (IWebElement result in Liste)
{
string link = result.GetAttribute("href");
lstSonuclar.Items.Add(link);
}
}
}
else MessageBox.Show("Lütfen aranacak bir kelime giriniz", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}