(Nov-17-2018, 12:08 AM)Truman Wrote: Thank you. One more thing - why in the second and third block of code you use .text for printing while you don't do that in the first example as it is a list.Because it's list that keep content,and list container has no method text.
Only content inside list are
bs4.element.tag
that have a text
method>>> red_text[3] <span class="red">First of all, dear friend, tell me how you are. Set your friend's mind at rest,</span> >>> # Look at type inside list >>> type(red_text[3]) <class 'bs4.element.Tag'> >>> # So it's a bs4.element that have method text >>> print(red_text[3].text) First of all, dear friend, tell me how you are. Set your friend's mind at rest,So if try to do this you see that it dos not make sense.
>>> lst = [] >>> lst.text Traceback (most recent call last): File "<interactive input>", line 1, in <module> AttributeError: 'list' object has no attribute 'text'
Quote:And are you saying that .findAll should not be used at all?
findAll()
and find_all()
both work and do the same in bs4.findAll()
is kept so older code can work(backward compatibility)CamelCase is bad style in Python,so don't use
findAll()
.