Python Forum
Automation WEB sel+Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Automation WEB sel+Python (/thread-28033.html)



Automation WEB sel+Python - ABVSVL - Jul-02-2020

Hi . Who can help me ?

There is a website.

I make a choice by // span [@ class = "basket-item__price-total_discount js__total-price"] of these 3 pieces

I added 3 books and went to the basket for verification.

How do I get the value 194 & nbsp and 5000 & nbsp into a variable and do the addition?
<span class="basket-item__price-total_discount js__total-price">194&nbsp;₽</span>

<span class="basket-item__price-total_discount js__total-price">5000&nbsp;₽</span>


you need to check the price of orders and the total price of the order


RE: Automation WEB sel+Python - snippsat - Jul-02-2020

You store tags in a variable,then a for loop over tags and use .text collect fixed result as show under in list.
Then use sum().
span_tag =  browser.find_elements_by_xpath('//span[@class="basket-item__price-total_discount js__total-price"]')
For one tag it would be.
>>> span_tag[0].text
'194 ₽'
# Fix so only get 194
>>> span_tag[0].text.split()[0]
'194'
# Integer
>>> int(span_tag[0].text.split()[0])
194



RE: Automation WEB sel+Python - ABVSVL - Jul-02-2020

how to check the amount of goods and add up all the goods to see if the total price is changing?


RE: Automation WEB sel+Python - snippsat - Jul-02-2020

(Jul-02-2020, 09:50 AM)ABVSVL Wrote: how to check the amount of goods and add up all the goods to see if the total price is changing?
This is what you should try yourself by using the code hint i have given,that how it's work here Wink
So to take it step further.
span_tag =  browser.find_elements_by_xpath('//span[@class="basket-item__price-total_discount js__total-price"]')
#print(span_tag)
total = []
for tag in span_tag:
    total.append(int(tag.text.split()[0]))

print(sum(total))
Output:
5194