I need to replace "!@#$%^&*()\n{}[]()_-+=<>?\xa0;'/.,
" with a blank. I am using replace method but it seems it is deprecated on python 3.6. word_list = []
is a list which will have all the words extracted from the webpage. Then clean_up_list
method will clean the symbols and replace them with blank space.
I used for
to loop through the length of symbols and replace symbols with blank. I used
word = word.replace(symbols[i],"")
; Any help on how to use the replace method so that symbols are replaced and words are printed without symbols between them.
Error:
AttributeError: 'list' object has no attribute 'replace'
My Code:
url = urllib.request.urlopen("https://www.servicenow.com/solutions-by-category.html").read()
word_list = []
soup = bs.BeautifulSoup(url,'lxml')
word_list.append([element.get_text() for element in soup.select('a')])
print(word_list)
def clean_up_list(word_list):
clean_word_list = []
for word in word_list:
symbols = "!@#$%^&*()\n{}[]()_-+=<>?\xa0;'/.,"
for i in range(0,len(symbols)):
word = word.replace(symbols[i],"")
#print(type(word))
#print(type(word))
#word.replace(symbols[i]," ")
if(len(word) > 0):
#print(word)
clean_word_list.append(word)