I've been making this script to extract prices from a shopping site to get opportunities for best prices,however idk why i can not remove spaces from lines tried strip and re but none seems to be working .
thanks for your answers
I'm a medical staff interested n programming that's why I'm not very skilled
Heres is the code :
import requests
from bs4 import BeautifulSoup
import re
file = open('weird.txt' , "w+" , encoding='utf8')
out = open("output.txt" , "w+" , encoding = 'UTF-8')
url = "https://www.lioncomputer.com/computer/computer-components/motherboard.html?lion_599=26179%2C26175&product_list_dir=asc"
page = requests.get(url)
page = page.text
soup = BeautifulSoup(page , 'html5lib')
file.write(soup.prettify())
soup2 = soup.find('ol' , class_ = 'products list items product-items')
item = soup2.find_all('div' ,class_ ="product details product-item-details")
for i in item :
name =i.find(class_= "product-item-link")
name = name.get_text()
price = i.find(class_="price-box price-final_price")
price = price.get_text()
# text = i.find('a' , class_ = 'product-item-link')
out.write(("{0}:{1}".format(name,price)))
with open('outpuT.txt' , "w+") as f :
for line in f:
cleaned = line.replace((re.find((' ')[6])), '')
cleaned = cleaned.strip()
f.write(cleaned)