[Solved] How to get similar tags in beautiful soup?


for a in soup.select("#listing-details-list li span"):

There is no problem with this line, assuming you’re trying to get all the span tags under the listing-details-list id. See:

for a in soup.select("#listing-details-list li span"):
    print a
<span> Property Reference: </span>
<span> Furnished: </span>
<span> Listed By: </span>
<span> Rent Is Paid: </span>
<span> Building: </span>
<span> Amenities: </span>
<span>Listed by:</span>

Your problem is that you are trying to print the results of an append call:

print spans_others.append(a.text)

and list.append always returns None (it mutates the list, it doesn’t return anything).

a = [].append(4)

a is None
Out[19]: True

So either print spans_others after you’re done appending to it, or print(a), or etc.

3

solved How to get similar tags in beautiful soup?