-2

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)
Jan
  • 42,290
  • 8
  • 54
  • 79
Bullet
  • 28
  • 3

1 Answers1

1

You can use the replace function in python to remove blank spaces.

newUpdatedString = oldString.replace("  ","")

However, also keep in mind that this command will remove all consecutive spaces.

Adarsh C
  • 118
  • 4
  • Tried but not working can you please run the code i get spaces which is a part of title in site i checked there is a Title = "stuff im looking for "but dont know how to get it – Bullet May 11 '20 at 09:06
  • The site you're trying to access is returning a 403 forbidden code. I can't do much with that :( – Adarsh C May 11 '20 at 09:13
  • Ah sryy iranian security logic :dont let them connect from foreign ip incase got hacked we can easily find lol i can send page source if u want – Bullet May 11 '20 at 09:18