Home > OS >  Web scraping Selenium Python project, TypeError: can't multiply sequence by non-int of type �
Web scraping Selenium Python project, TypeError: can't multiply sequence by non-int of type �

Time:07-23

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:

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?

CodePudding user response:

print(standard_price * float(new_price))
  • Related