我只想从Wiki页面上抓取电影标题,请帮助我
我的代码:
url = 'https://en.wikipedia.org/wiki/List_of_American_films_of_2020'
page = requests.get(url)
soup = BeautifulSoup(page.content,'html.parser')
movies = soup.find('table',{'class':'wikitable sortable'})
print(movies)
我只想从结构中过滤掉电影标题,就像图像中的电影标题应该只是“丢失的传输”
答案 0 :(得分:1)
您可以进一步处理废弃的表格。
table_body = movies.find('tbody')
titles = []
rows = table_body.find_all('tr')
for row in rows[1:]: # leaving the first row, seems it is a header
title_cell = row.select("td i a")
titles.append(title_cell[0].contents[0])
print(titles)
答案 1 :(得分:0)