单击按钮后,我试图获得网站给出的值。
这是网站: https ://www.4devs.com.br/gerador_de_cpf
可以看到有一个叫“Gerar CPF”的按钮,这个按钮提供了一个点击后出现的数字。
我当前的脚本打开浏览器并获取值,但我是在单击之前从页面获取值,因此该值为空。我想知道是否有可能在点击按钮后获得价值。
from selenium import webdriver
from bs4 import BeautifulSoup
from requests import get
url = "https://www.4devs.com.br/gerador_de_cpf"
def open_browser():
driver = webdriver.Chrome("/home/felipe/Downloads/chromedriver")
driver.get(url)
driver.find_element_by_id('bt_gerar_cpf').click()
def get_cpf():
response = get(url)
page_with_cpf = BeautifulSoup(response.text, 'html.parser')
cpf = page_with_cpf.find("div", {"id": "texto_cpf"}).text
print("The value is: " + cpf)
open_browser()
get_cpf()
原文由 user6866656 发布,翻译遵循 CC BY-SA 4.0 许可协议
open_browser
和get_cpf
绝对没有关系……实际上你根本不需要
get_cpf
。单击按钮后只需等待文本:更新
与请求相同: