Jump to content
Admin

Hướng dẫn sử dụng thư viện Selenium với CSharp

Recommended Posts

19 giờ trước, info259 said:

 

Ớ ơ.. tớ nhớ hình như mở được lần lượt từng tab thôi :c15: ý bạn là mở nhiều tab của 1 chrome hay là nhiều chrome 1 lúc ?

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

Hướng dẫn các bạn tạo multipe profile, chạy nhiều profile một lúc và sắp xếp theo hàng theo lối .

Bước 1 : các bạn phải tạo ra 1 loạt profile mới, có đường dẫn không chung nhau, code tạo profile

 string Folder_Profile_Rieng =  @"\data\Ten_Profile";
if (!Directory.Exists(Folder_Profile_Rieng))
{
  Directory.CreateDirectory(Folder_Profile_Rieng);
  ChromeDriverService Cds = ChromeDriverService.CreateDefaultService();
  Cds.HideCommandPromptWindow = true;
  ChromeOptions ChOpt = new ChromeOptions();
  ChOpt.AddArgument(@"--profile-directory=Default");
  ChOpt.AddArgument(@"--user-data-dir=" + Application.StartupPath + Folder_Profile_Rieng);
  IWebDriver driver = new ChromeDriver(Cds, ChOpt)
  {
    Url = "https://www.teamcodedao.com/forum"
  };
}
else
{
  MessageBox.Show("Profile này đã tạo rồi", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

Bước 2 : sau khi có 1 đống profile mới, với đường dẫn không bị trùng nhau, các bạn mới có thể chạy multipe được. Code multipe profile như sau : 

for(int j = 0; j < 2; j++)
{
	for (int i = 0; i < 3; i++)
    {
      int SoCot = i;
      int SoHang = j;
      Thread t = new Thread(() =>
      {
		OpenChrome(SoCot,SoHang);
      });
      t.Start();
    }
}

Hàm OpenChrome(SoCot, SoHang) như sau : 

private void OpenChrome(int SoCot, int SoHang)
{
  ChromeDriverService service = ChromeDriverService.CreateDefaultService();
  service.HideCommandPromptWindow = true;
  ChromeOptions options = new ChromeOptions();
  ChOpt.AddArgument(@"--profile-directory=Default");
  ChOpt.AddArgument(@"--user-data-dir=" + Application.StartupPath + Folder_Profile_Rieng); // Đoạn này các bạn tùy biến cho đường dẫn profile vào cho đúng nhé.Nếu bị trùng nhau sẽ báo lỗi.
  options.AddArgument($"--window-size=300,350");            
  IWebDriver web = new ChromeDriver(service, options);            
  web.Manage().Window.Position = new Point(300 * SoCot, 350*SoHang);
  string url = "https://www.google.com/";
  web.Navigate().GoToUrl(url);
}

Chả biết lỗi gì không =.='' nhưng thế đã.. lỗi các bạn báo lại ,mỵ fix nhé...

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

cảm ơn bác

các bác cho e hỏi có cách nào set proxy có username và password chạy ẩn mà k cần AddExtension bằng selenium k v các bác

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

Chào các anh chị, cho em hỏi ngu là các tiền bối viết tool tạo email tự động, reg nick, comment tương tác shopee.. thì dùng cái selenium này để giả lập đúng không ạ. Em cũng đang vọc vạch mà thắc mắc đoạn này, còn việc đổi cấu hình máy và địa chỉ mạng để không bị phát hiện là spam nữa :D. Em cảm ơn ạ.

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites
53 phút trước, SniperKiller said:

Chào các anh chị, cho em hỏi ngu là các tiền bối viết tool tạo email tự động, reg nick, comment tương tác shopee.. thì dùng cái selenium này để giả lập đúng không ạ. Em cũng đang vọc vạch mà thắc mắc đoạn này, còn việc đổi cấu hình máy và địa chỉ mạng để không bị phát hiện là spam nữa :D. Em cảm ơn ạ.

đúng rồi :v nhưng gần đây, hầu hết trang web lớn đều có thể phát hiện ra mình xài cái này nên mới cần tìm hiểu thêm về đổi thông tin máy :v bạn tìm hiều từ từ ..quãng đường còn dài và rộng lắm...:a19:

Chia sẻ bài đăng này


Link tới bài viết
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Trả lời chủ đề này...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...