Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.findAll()
#9
(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().
Reply


Messages In This Thread
.findAll() - by Truman - Nov-14-2018, 10:42 PM
RE: .findAll() - by Gribouillis - Nov-14-2018, 10:49 PM
RE: .findAll() - by Truman - Nov-14-2018, 10:52 PM
RE: .findAll() - by Gribouillis - Nov-14-2018, 11:05 PM
RE: .findAll() - by Truman - Nov-16-2018, 12:21 AM
RE: .findAll() - by snippsat - Nov-14-2018, 11:37 PM
RE: .findAll() - by snippsat - Nov-16-2018, 12:51 PM
RE: .findAll() - by Truman - Nov-17-2018, 12:08 AM
RE: .findAll() - by snippsat - Nov-17-2018, 01:27 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  re.findall help searching for string in xml response mugster 2 3,279 May-30-2018, 03:27 PM
Last Post: mugster
  Different Output of findall and search in re module shiva 1 2,348 Mar-12-2018, 08:39 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020