且构网

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

beautifulsoup]清单对象没有属性"错误

更新时间:2022-04-29 22:54:33

.findAll()方法返回一个匹配的列表的。如果你想的有一个的结果,使用 .find()方法来代替。另外,挑选出一个特定的元素,如code做的其余部分,或者遍历结果:

The .findAll() method returns a list of matches. If you wanted one result, use the .find() method instead. Alternatively, pick out a specific element like the rest of the code does, or loop over the results:

location = soup.find('h1').text

locations = [el.text for el in soup.findAll('h1')]

location = soup.findAll('h1')[2].text