Answer the question
In order to leave comments, you need to log in
How to make a nickname parser from a chat?
Hello, I am writing a parser for a chat on the site, but when I start the program, it gives an error
IndexError: list index out of range
Please tell me what is the error and how to solve it.
import requests
from bs4 import BeautifulSoup as BS
c = '''parser for
'''
print (c)
r = requests.get(')
html= BS(r.content, 'html.parser')
for el in html.select('.msg'):
title = el.select('.superuser > a')
print( title[0].text )
Answer the question
In order to leave comments, you need to log in
.superuser
nested in <a>
, not vice versa.
for el in html.select('.msg'):
title = el.select('a > .superuser')
if title:
print( title[0].text )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question