H
H
Hectora2020-06-05 17:51:57
Python
Hectora, 2020-06-05 17:51:57

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

1 answer(s)
S
soremix, 2020-06-05
@Hectora

.superusernested in <a>, not vice versa.

for el in html.select('.msg'):
    title = el.select('a > .superuser')
    if title:
        print( title[0].text )

ps: spoiler - the whole chat is most likely fake. And I strongly doubt that it will be updated every time in the page code. If you really need nicknames all the time, then it's better to send a POST to the update.php endpoint with all the data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question