Answer the question
In order to leave comments, you need to log in
How to get rid of comma when parsing data?
You just need to get rid of the comma in the dictionary in name, there is a comma after the name:
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('div', class_ ='_227VT')
otzivi = []
for item in items:
otzivi.append(
{
'name': item.find('div', class_='_1tvOC r2Q86').find('div', class_='_3qkdy _7QkVd').find('div', class_='_3bNvn').find('div', class_='_1ubS9 yHpsJ').find('div', class_='_2iHTj').find('span').get_text(),
'nameotziva': item.find('div', class_='_1tvOC r2Q86').find('div', class_='_3qkdy _7QkVd').find('a', class_='mrfZC').find('div', class_='_3SgnA _2mg0e').get_text(),
'link': item.find('div', class_='_1tvOC r2Q86').find('div', class_='_3qkdy _7QkVd').find('a', class_='mrfZC').get('href'),
'text': item.find('div', class_='_1tvOC r2Q86').find('div', class_='_3qkdy _7QkVd').find('div', class_='_3p0dD').find('span').find('p').get_text()
}
)
return otzivi
html = get_html(URL)
print(get_content(html.text))
Answer the question
In order to leave comments, you need to log in
Where???
Wang like this - after get_text () use replace:
if there is an error, then like this:
Well, this is all fortune-telling on the coffee grounds.
get_text().replace(',','')
.text().replace(',','')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question