更新时间: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