I want to change all these : '/' to this : ' / ' and looking for the value before the / and insert a space character. (So iv got this : '8/3' and i want this : ' 8 / 3 ') This is my code:
datatable=[]
stop = 0
for ctable in soup.find_all('table', "ctable" ):
for record in ctable.find_all('tr'):
temp_data = []
for data in record.find_all('td'):
temp_data.append(data.text.encode('latin-1'))
if '/' in data.text:
record2 = str(record).replace('/', ' / ')
final_format = ' {} '.format(record2)
if 'modul' in data.text:
stop = 1
break
datatable.append(temp_data)
if stop == 1:
break
if stop == 1:
break
output.writerows(datatable)
How can i reach it?
record.replaceisn't doing anything, but your error seems to indicate thatrecordis set to Nonerecord.replaceworks you are not storing it anywhere or using it afterwards so the line basically does nothing to affect the outcome of the code. Maybe it is easier if you just get your data from the soup and then in a different loop correct it.data2 - data.text.replace('/', ' / ')