我有这个硒代码
x = browser.find_element_by_xpath('//*[@id="paginacaoSuperior"]/tbody/tr[1]/td[1]/h2/span').text
此代码将此值返回给我
result 1 to 299
我想删除这些值
result 1 to
只剩下299
使用此值299
除以12
y = 'Result1to'
for i in range(0,len(x)):
x = x.replace(y[i],"")
print(x)
我使用了此代码,但给出了错误
使用带有负索引的str.split
。
前任:
s = "result 1 to 299"
print(s.split()[-1]) # -->299
执行以下操作以解决问题:
s = "result 1 to 299"
print(round(int(s.split()[-1])/12, 4))
# first action is s.split() we devide string and get list
# s.split()[-1] take the last element of the list
# int(s.split()[-1]) convert it to integer (you can use float instead)
# round(int(s.split()[-1])/12, 4) divide by 12 and show only 4 digits after point