【问题标题】:How to automate captcha using Selenium Webdriver? [closed]如何使用 Selenium Webdriver 自动化验证码? [关闭]
【发布时间】:2016-03-08 05:52:30
【问题描述】:

我正在为登录页面编写脚本。但我有一个我想处理的验证码。

【问题讨论】:

  • 你不能绕过验证码,这就是它的存在!!

标签: selenium selenium-webdriver


【解决方案1】:

Selenium 无法处理验证码。

虽然网站出于同样的原因使用验证码,所以没有人可以使用任何机器人自动化他们的网站。

您可以要求您的开发人员为您提供特殊环境,让他们绕过验证码功能或在 DOM 上公开验证码值,以便您可以在运行时获取验证码值。

有一些第三方库声称他们也可以自动化验证码,但我从未尝试过并且听说它们效率也不高。

一些参考资料:- How to read the text from image (captcha) by using Selenium WebDriver with Java

http://www.mythoughts.co.in/2012/11/automatingbreaking-captcha-using.html#.Vt5psdx94x8

【讨论】:

    【解决方案2】:

    大多数验证码求解器都是付费的。验证码解决的几个例子是:

    • 验证码死亡
    • 2验证码
    • 反验证码
    • 破译者

    tesseract 库解决了验证码中的一些简单示例。

    【讨论】:

      【解决方案3】:

      在这里,试试我的方法(在 c 中):

      public void GenerateSnapshot(string filePath)
      {
          IWebDriver driver = new ChromeDriver();
          driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl(“your url here”);
          var remElement = driver.FindElement(By.Id(“your Captcha Id here”));
          Point location = remElement.Location;
          var screenshot = (driver as ChromeDriver).GetScreenshot();
          using(MemoryStream stream = new MemoryStream(screenshot.AsByteArray))
          {
              using(Bitmap bitmap = new Bitmap(stream))
              {
                  RectangleF part = new RectangleF(location.X, location.Y, remElement.Size.Width, remElement.Size.Height);
                  using(Bitmap bn = bitmap.Clone(part, bitmap.PixelFormat))
                  {
                      bn.Save(filePath + “CaptchImage.png”, System.Drawing.Imaging.ImageFormat.Png);
                  }
              }
          }
      
          //reading text from images
          using(var engine = new TesseractEngine(“tessdata path here”, “eng”, EngineMode.Default))
          {
      
              Page ocrPage = engine.Process(Pix.LoadFromFile(filePath + “CaptchImage.png”), PageSegMode.AutoOnly);
              var captchatext = ocrPage.GetText();
          }
      }
      

      来源:https://thedotnetlight.wordpress.com/2018/02/16/read-captcha-image-in-selenium-c/

      【讨论】:

      • 仅链接的答案通常是 Stack Overflow 上的frowned upon。随着时间的推移,链接可能会萎缩并变得不可用,这意味着您的答案将来对用户毫无用处。如果您可以在实际帖子中提供答案的一般详细信息,并引用您的链接作为参考,那将是最好的。
      猜你喜欢
      • 2021-09-17
      • 1970-01-01
      • 2021-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 2017-01-27
      相关资源
      最近更新 更多