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

330
Visualizações
Get value after button click with python

I'm trying to get a value that is given by the website after a click on a button.

Here is the website: CPF generator website

You can see that there is a button called "Gerar CPF", this button provides a number that appears after the click.

My current script opens the browser and get the value, but I'm getting the value from the page before the click, so the value is empty. I would like to know if it is possible to get the value after the click on the button.

from selenium import webdriver
from bs4 import BeautifulSoup
from requests import get

url = "https://www.4devs.net.br/gerador-cpf"

def open_browser():
    driver = webdriver.Chrome("/home/willi/Documents/chromedriver")
    driver.get(url)
    driver.find_element_by_class('btn m-1 btn-primary btn-sm').click()

def get_cpf():
    response = get(url)

    page_with_cpf = BeautifulSoup(response.text, 'html.parser')

    cpf = page_with_cpf.find("input", {"id": "__BVID__61"}).text

    print("The value is: " + cpf)


open_browser()
get_cpf()
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could simply add a while loop in order to update the value at a time you desire. For example:

import time
from selenium import webdriver
from bs4 import BeautifulSoup
from requests import get

url = "https://www.4devs.net.br/gerador-cpf"

def open_browser():
  driver = webdriver.Chrome("/home/willi/Documents/chromedriver")
  driver.get(url)
  driver.find_element_by_class('btn m-1 btn-primary btn-sm').click()

def get_cpf():
  response = get(url)

  page_with_cpf = BeautifulSoup(response.text, 'html.parser')

  cpf = page_with_cpf.find("input", {"id": "__BVID__61"}).text

  print("The value is: " + cpf)

while True:
   open_browser()
   get_cpf()
   time.sleep(your_time_in_s)
about 4 years ago · Juan Pablo Isaza Relatório

0

The following code works using part of Ruggero's solution and pyperclip:

import time
import pyperclip
from selenium import webdriver
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
from requests import get
import chromedriver_binary  # Adds chromedriver binary to path

url = "https://www.4devs.net.br/gerador-cpf"
your_time_in_s=2

def open_browser():
    driver = webdriver.Chrome()
    driver.get(url)
    driver.find_element(By.XPATH, '//*[@id="app"]/div/div[2]/div/div/div[3]/div/div[3]/div[1]/div/button[2]').click()
    time.sleep(your_time_in_s)
    driver.find_element(By.XPATH, '//*[@id="__BVID__60"]/div/div/div/button').click()
    print("The value is: " + pyperclip.paste())

while True:
    open_browser()
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