Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

329
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!