Getting value after button click with BeautifulSoup Python Getting value after button click with BeautifulSoup Python selenium selenium

Getting value after button click with BeautifulSoup Python


open_browser and get_cpf are absolutely not related to each other...

Actually you don't need get_cpf at all. Just wait for text after clicking the button:

from selenium.webdriver.support.ui import WebDriverWait as waitdef open_browser():    driver = webdriver.Chrome("/home/felipe/Downloads/chromedriver")    driver.get(url)    driver.find_element_by_id('bt_gerar_cpf').click()    text_field = driver.find_element_by_id('texto_cpf')    text = wait(driver, 10).until(lambda driver: not text_field.text == 'Gerando...' and text_field.text)    return textprint(open_browser())

Update

The same with requests:

import requestsurl = 'https://www.4devs.com.br/ferramentas_online.php'data = {'acao': 'gerar_cpf', 'pontuacao': 'S'}response = requests.post(url, data=data)print(response.text)


You don't need to use requests and BeautifulSoup.

from selenium import webdriverfrom time import sleepurl = "https://www.4devs.com.br/gerador_de_cpf"def get_cpf():    driver = webdriver.Chrome("/home/felipe/Downloads/chromedriver")    driver.get(url)    driver.find_element_by_id('bt_gerar_cpf').click()    sleep(10)    text=driver.find_element_by_id('texto_cpf').text    print(text)get_cpf()


Can you use a While loop until text changes?

from selenium import webdriverurl = "https://www.4devs.com.br/gerador_de_cpf"def get_value():    driver = webdriver.Chrome()    driver.get(url)    driver.find_element_by_id('bt_gerar_cpf').click()    while driver.find_element_by_id('texto_cpf').text == 'Gerando...':        continue    val = driver.find_element_by_id('texto_cpf').text    driver.quit()    return valprint(get_value())