先说结论:拼写大小写错误。BeatufulSoup并没有findall(),但有findAll()。
而BS4推荐使用find_all(),这个findAll仅仅是为了兼容BS3,
事情是这样的:
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
换成findChildren则成功:
soup = BeautifulSoup(html, 'html.parser')
trs = soup.find(id="grid").find("tbody").findAll("tr")
for tr in trs:
tds = tr.findChildren()
一阵莫名奇怪,排查才发现,原来是大小写拼写错误。