셀레니움 C# 설치 및 사용법

모카쨩 2024. 4. 21. 19:46

 

 

 

 

 

Selenium.WebDriver입력후 설치

 

 

 

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;

public static class Crawling
{
    public static void Run()
    {
        driver = new ChromeDriver();

        driver.Url = "https://www.google.com";
        driver.FindElement(By.Name("q")).SendKeys("webdriver" + System.Windows.Forms.Keys.Return);
        Console.WriteLine(driver.Title);

        driver.Quit();
    }
}

 

그리고 코드 만들어서 실행하면 된다

이 코드는 아래 공식사이트의 기본 예제이다

https://www.nuget.org/packages/Selenium.WebDriver

 

Selenium.WebDriver 4.19.0

Selenium is a set of different software tools each with a different approach to supporting browser automation. These tools are highly flexible, allowing many options for locating and manipulating elements within a browser, and one of its key features is th

www.nuget.org

 

 

 

그리고 쪼~끔 비직관적인 예제길래 내가 이런 예제로 만들었다

namespace Crawler
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        Crawling crawling = new Crawling();
        private void button1_Click(object sender, EventArgs e)
        {
            crawling.Run();
        }
    }
}
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;

namespace Crawler
{
    public class Crawling
    {
        ChromeDriver driver;
        public void Run()
        {
            driver = new ChromeDriver();

            driver.Url = "https://www.google.com";
            driver.Quit();
        }
    }
}