Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
Captcha image cropped on the left side

update: I manually changed cnv.width = this.width to 120 and it kind of works. I also found that the image has rendered size and intrinsic size. Width is 35 for rendered size and 40 for intrinsic size, so I guess this could be the reason.

I am trying to use selenium to get captcha image from a web page. Here is what I have tried based on examples from this site

def get_ver_code(driver):
    img = driver.find_element(By.XPATH, '//*[@id="imgCode"]')
    img = driver.execute_async_script("""
        var ele = arguments[0], callback = arguments[1];
        ele.addEventListener('load', function fn(){
          ele.removeEventListener('load', fn, false);
          var cnv = document.createElement('canvas');
          cnv.width = this.width; cnv.height = this.height;
          cnv.getContext('2d').drawImage(this, 0, 0);
          callback(cnv.toDataURL('image/jpeg').substring(22));
        }, false);
        ele.dispatchEvent(new Event('load'));
        """, img)
    with open(r"captcha.jpg", 'wb') as f:
        f.write(base64.b64decode(img))
        
    base64_decoded = base64.b64decode(img)
    img = Image.open(io.BytesIO(base64_decoded))
    img = np.array(img)
    return img

This is almost fine, except that the images downloaded are always slightly cropped on the right side. A lot of times it doesn't affect the digits, but sometimes it does. For example: enter image description here

How can I fix this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Looks like it has something to do with the width & height of the elem. you putting the img into. Is there maybe some margin applied by some other css?

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda