[Python] BeautifulSoup in Python find() works as unexpected way with tuples

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024.

  1. Stack

    Stack Membro Participativo

    I am practicing crawling web, and yesterday I had an unexpected correct result which I dont think it should be work.

    I used soup.find(id=i) to find the attribute key i, I though i must be string, but when I passed a tuple - which is first element of tuple is string that is key, and I was surprise when it still ran correct result.

    let say '01' is the key of attribute, the code below had exact result with id='01' tup = ('01', 'Revenue') acc = soup.find(id=tup).text.strip().split('\n')

    Who has experience on this matter, please help me to explain? Thank you so much.

    What I tried:

    tup = ('01', 'Revenue')
    acc = soup.find(id=tup).text.strip().split('\n')


    I expect the KeyError because I passed a tuple instead of a string to id.

    Continue reading...

Compartilhe esta Página