I want to scrape last word of a sentence defined in a span using selenium python. I am able to get the whole sentence using this:-
elements = browser.find_element_by_css_selector("span[ng-if='!product.product.isOnlyCarCategory']");
print elements
result = elements.text
print result
Output:- Buy for Rs 329
I want only 329 to be output not the whole sentence. I've tried using replace function of python and able to achieve what I want like this:-
elements = browser.find_element_by_css_selector("span[ng-if='!product.product.isOnlyCarCategory']");
print elements
result = elements.text
result = int(result.replace('Buy for Rs ',''))
print result
Output:- 329
but I don't want to use replace function. I want to use selenium to do the same. And yes this integer value is dynamic
Is there any way to do that?
splitthe string by space and get the last element?