[Python] AttributeError:'NoneType' object has no attribute'find_all' error and find_all function

I encountered a very strange problem today (Are all problems called strange? I don’t know hahaha), but I still don’t understand what the problem is. I think it’s necessary to record it. Wan One day when I met, I thought that the big guy and the big god took a look at my blog and gave me a benevolent answer? Hahahaha, look forward to that day ! No matter how bad, I might be able to solve it myself in a few years, hahaha, come on, little friends!

AttributeError: 'NoneType' object has no attribute 'find_all'错误 

It is this line that reports an error, yes.

I also searched the Internet for a while, but I still couldn't find a solution for me. Some said it was caused by the difference between static webpages and dynamic webpages, and some Barabara couldn't remember it.

Later, I checked and found that the find_all function still has so many siblings. It’s terrible. Find doesn’t count. There are also findAll and findall. The similarity between the two is too high. I had to go and see what these are all doing, so I have:

First of all

findall function

It is a commonly used function under the re template. . . Speaking of this, it seems to be a bit familiar, yes, that is, that regular expression always knows, yes, the powerful matching function, can’t help but praise! However, this way of expression is a bit incomprehensible.

If you are interested, you can go to the rookie tutorial: https://www.runoob.com/python/python-reg-expressions.html , thank you very much!

Having said so much, it seems that it has nothing to do with our formality, hahaha, don't worry, continue to look down!

findAll function 

I am a little afraid to say this. . . What seems to be? I haven't found all the official positive information. It should be a function defined by others. OK, skip this paragraph.

 

find_all function

Then quickly take a look at the main one, not to mention whether the main one will be sprayed? ? , Fortunately, fortunately, there are not so many people paying attention, I will be happy! ,

After looking around, I finally found the introduction of the official document. Just one sentence: search for all tag child nodes that match the current tag, and return a list.

So seeing this, the code I wrote before has no problems at all:

 However, the error was reported ruthlessly!

What is even more puzzled is the following solution: Is there any difference in the way of passing parameters? I am too ignorant. . .

 I hope to meet a kind-hearted person to help me answer my questions, thank you!

I also hope that people behind will not step on the pit

Guess you like

Origin blog.csdn.net/weixin_44566432/article/details/107864278