Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

331
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda