在该站点中,有一个特定类包含一个数学公式,如:
7-6=
15 x 8=
3 x(5-2)=
<div tabindex="20" dir="ltr" class="card-title">3 x (5 - 2) =</div>
如何导出硒元素含量并对其进行溶解
我的代码:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
PATH = "H:/python/venv/chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options, executable_path=r'H:/python/venv/chromedriver.exe')
driver.get("https://freerice.com/categories/basic-math-pre-algebra")
driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/div[1]/button").click()
driver.implicitly_wait(10)
feladat = str(driver.find_element_by_xpath("/html/body/div[2]/section/div/div[1]/div/div[2]/div[4]/div[1]/div/div/div/div/div/div[1]").text)
megoldas = [feladat]
lista = []
for c in feladat:
if c.isdigit():
lista = lista + [c]
else:
lista = lista + [c]
print(lista)
我知道你的解决方案是什么了-把所有的字符分开,识别数字,然后(我想)你会找到所有的数学运算符
有一个更简单的方法
eval
和exec
函数接收字符串并计算输出。只要该字符串有效,它就会工作我使用了
eval
作为我第一次键入它,它工作了。如果你需要了解更多,谷歌搜索这两个根据您的输入:
典型的语法是
x = 1 + 1
。 我们需要:我们的做法如下:
输出为:
查看您的站点,并使其与您当前的方法保持一致,我将按如下方式更新它:
我还更新了标识符以便更容易理解
相关问题 更多 >
编程相关推荐