python3 nonetypefind_Python属性错误:“NoneType”对象没有“find\u all”属性

source.first()只返回第一个元素。

引用的first()方法的源代码:def find(self, name=None, attrs={}, recursive=True, text=None, **kwargs):

"""Return only the first child of this Tag matching the given criteria."""

r = None

l = self.find_all(name, attrs, recursive, text, 1, **kwargs)

if l:

r = l[0]

return r

findChild = find

在提取表之后,它的类名是wikitable sortable。

所以按照上面的代码,它返回None。

所以你可能想把你的代码改成。。。from bs4 import BeautifulSoup

from urllib.request import urlopen

url = 'https://simple.wikipedia.org/wiki/List_of_U.S._states'

web = urlopen(url)

source = BeautifulSoup(web, 'html.parser')

table = source.find('table', class_='wikitable')

abbs = table.find_all('b')

abbs_list = [i.get_text().strip() for i in abbs]

print(abbs_list)

我希望它能回答你的问题。:)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值