且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

line = line.strip() TypeError: 'NoneType' 对象不可调用

更新时间:2022-06-15 03:59:36

那是因为您正试图在 beautiful Soup 中的标签类上运行 strip.

That's because you are trying to run strip on the tag class within beautiful soup.

将第 14 行更改为:

Change line 14 to:

 line = line.string.strip()

但是请注意,当您搜索的标签具有多个子元素时,这仍然可以是 None.请参阅 链接到 doco 上的字符串方法以获得美丽的汤

However be aware that this can still be None when the tag you are searching for has multiple sub elements. Seee link to string method on doco for beautiful soup