Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Web scraping Selenium Python project, TypeError: can't multiply sequence by non-int of type 'list'

I’m new to programming with Python and I’m trying to learn by doing projects.

I’m working on a web scraping project with Python Selenium. I need to get a variable price from a website for airplane tickets, and need to calculate how many times the standard (bottom price) fits into the new price. I need a result like: 1.5x, 1,6, 2.0x etc.

I managed to get the variable prices into the terminal, but when I run the calculation it gives me this error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

standard_price = 0.0411

new_price = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[1]/div/div[2]/div[2]/div/span/div/div[3]/div/div[1]/div[2]/div[1]/div[2]/div').text

price_content = price.get_attribute('innerHTML')

emp_str = ""
for m in price_content:
    if m.isdigit():
        emp_str = emp_str + m
print(standard_price * emp_str)

I put the ‘isdigit’ function so it will only output numbers. When I run it, it gives me 4 digit number, so that is good.

But when i run the code

print(standard_price * new_price)

I get this error: TypeError: can’t multiply sequence by non-int of type ‘list’

I know that it has to do something with the fact that standard_price is a float, and new_price is a list, I tried a lot of things, also checked out older questions on the forum but with no results.

Is there a practical workaround?

>Solution :

print(standard_price * float(new_price))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading