Python Selenium Webelement 浮动 [英] Python Selenium Webelement to Float

查看:59
本文介绍了Python Selenium Webelement 浮动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下问题:我正在尝试将我的 webelement 转换为浮动.

I'm having the following issue: I'm trying to convert my webelement to float.

asd = driver.find_element_by_xpath("/html/body/div[2]/div[4]/div[2]/div[2]/div[2]/div/div/div/table/tbody/tr[3]/td[17]")

print (float(asd.text.strip()))

出现此错误:

    print (float(asd.text.strip()))
ValueError: could not convert string to float: '3,56'

谢谢!

推荐答案

字符串不是python识别的浮点格式.您可以将其更改为句点(使用 float(asd.text.strip().replace(",", ".")) 或使用 locale:

The string is not in the float format that python recognizes. You can either change it to a period (using float(asd.text.strip().replace(",", ".")) or using locale:

from locale import atof, setlocale, LC_NUMERIC
setlocale(LC_NUMERIC, "YOURLOCALE") # a locale where commas are used as the decimal point
atof(asd.text.strip())

无论使用哪种方法,您都必须确保运行代码的所有网站/页面的语法一致.

Either method you use, you have to make sure the syntax is consistent over all the sites/pages you run your code on.

这篇关于Python Selenium Webelement 浮动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆