Content is served dynamically, so you wont get it this way with requests
- Take a look at this selenium
code.
To get rid of text and spaces you can do:
.get_text(strip=True).replace('Was: ','')
Example
from selenium import webdriver
from bs4 import BeautifulSoup
import time
url = "https://www.petshop.co.uk/Dog"
driver = webdriver.Chrome('C:Program FilesChromeDriverchromedriver.exe')
driver.get(url)
time.sleep(3)
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')
for old_price in soup.find_all("small", class_ = "product-views-price-old"):
print(old_price.get_text(strip=True).replace('Was: ',''))
driver.quit()
Output
£2.20
£18.61
£27.00
£38.39
£38.39
£20.65
£1.30
£67.99
£20.65
£1.30
£54.95
£30.99
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…