【发布时间】:2025-11-25 18:50:01
【问题描述】:
import requests
from bs4 import BeautifulSoup
wiki = "https://en.wikipedia.org/wiki/List_of_Pixar_films"
website_url = requests.get(wiki).text
soup = BeautifulSoup(website_url, 'lxml')
table_class = "wikitable plainrowheaders sortable"
my_table = soup.find('table', {'class': table_class})
Film = []
release = []
for row in my_table.find_all('i')[0:]:
Film_cell = row.find_all('a')[0]
Film.append(Film_cell.text)
print(Film)
for row in my_table.find_all('td')[0:]:
release = row.find_all('span')[:1]
release.append(release.text)
print(release)
输出:
['Toy Story', "A Bug's Life", 'Toy Story 2', 'Monsters, Inc.',
'Finding Nemo', 'The Incredibles', 'Cars', 'Ratatouille', 'WALL-E',
'Up', 'Toy Story 3', 'Cars 2', 'Brave', 'Monsters University', 'Inside Out',
'The Good Dinosaur', 'Finding Dory', 'Cars 3', 'Coco', 'Incredibles 2',
'Toy Story 4', 'Onward', 'Soul', 'Luca', 'Turning Red', 'Lightyear']
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-223-6481bc092354> in <module>
7 for row in my_table.find_all('td')[0:]:
8 release = row.find_all('span')[:1]
----> 9 release.append(release.text)
10 print(release)
AttributeError: 'list' object has no attribute 'text'
【问题讨论】:
标签: python list web-scraping beautifulsoup