So effectively, to strip the %, convert the string to float and print, your effective line of code will be: are still seeing the error as the element with the required text haven't rendered within the DOM when the line of code is invoked. My_string_num = my_percentage.split("%")įurther, find_element_by_xpath() will identify only a single element, and using text you would get a single string, so string = " ".join(list) seems redundant. text method would return a string and to strip off the %, instead of string.split('%') you want list = string.split('%'). implies that the Python interpreter was unable to convert a string to float. ValueError: could not convert string to float: '' Oh and if you want to see the entire code, it's here: And when I isolate the problem, it works fine. Even worst, it works sometimes, for no reason. When I try to isolate the problem by running a simplified version of the program like this : a = "-0.06%"ĭef removeprc(string): #removes the % from a string As you can see, I think it's not the case here. I've read on the internet that this can happen if you try to float() things that are not numbers or that have weird shit in them, like spaces. That's the weirdest thing about this, it works perfectly half the time! on the 6th line, I printed what i am trying to get the float() įile "C:\Users\pc adam\Documents\EISTI\algoprog\perso\python\fichiers\btc\ETHtradingbotV1.py", line 138, in It's probably not the best way to do it, but it works when I test it alone.Īnyway, here is what I get when I run my entire code loading page. "remove prc" is a little function I created to remove the % of a number, here it is: def removeprc(string): #removes the % from a string as you will see later, the element retrieved is a number which should work with float() Ok so here is the code posing problem: old_values = is a selenium tool used to get a value of a website. It seems to be a common problem, but I've never seen it asked in the same situation I'm in. I'm coding a little bot in Python and I'm having a problem.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |