先说结论:拼写大小写错误。BeatufulSoup并没有findall(),但有findAll()。
而BS4推荐使用find_all(),这个findAll仅仅是为了兼容BS3,
![](https://img-blog.csdnimg.cn/img_convert/7fdea9729aa1f7fc65db2390eb2e3d0e.png)
事情是这样的:
soup = BeautifulSoup(html, 'html.parser')
trs = soup.find(id="grid").find("tbody").findAll("tr")
for tr in trs:
tds=tr.findall("td")
BeautifulSoup 执行tds=tr.findall("td")报错: TypeError: 'NoneType' object is not callable
![](https://img-blog.csdnimg.cn/img_convert/b95daabc1c66ceb9ed2c0f10fc2cf5be.png)
换成findChildren则成功:
soup = BeautifulSoup(html, 'html.parser')
trs = soup.find(id="grid").find("tbody").findAll("tr")
for tr in trs:
tds = tr.findChildren()
一阵莫名奇怪,排查才发现,原来是大小写拼写错误。