[英]How can I replace a text delimited string list item with multiple list items in a python list?
[英]How can I replace string in a list with python?
我想將所有這些:'/'更改為:'/',然后在/之前尋找值,並插入一個空格字符。 (所以四得到這個:'8/3',我想要這個:'8/3')這是我的代碼:
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)
我如何到達?
該find_all
從功能bs4
沒有返回的字符串,但BS標簽,你需要記錄轉換為字符串,以使用替換法。
useful_string = str(record).replace('/', ' / ')
是要走的路。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.