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

336
Views
Obtener valor después de hacer clic en el botón con python

Estoy tratando de obtener un valor proporcionado por el sitio web después de hacer clic en un botón.

Aquí está el sitio web: sitio web del generador CPF

Puede ver que hay un botón llamado "Gerar CPF", este botón proporciona un número que aparece después del clic.

Mi secuencia de comandos actual abre el navegador y obtiene el valor, pero obtengo el valor de la página antes del clic, por lo que el valor está vacío. Me gustaría saber si es posible obtener el valor después de hacer clic en el botón.

 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

Simplemente puede agregar un ciclo while para actualizar el valor en el momento que desee. Por ejemplo:

 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

El siguiente código funciona con parte de la solución de Ruggero y 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!