Python(bs4) 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)

我只想从结构中过滤出电影标题,就像图像中的电影标题应该只是“丢失的传输”

这是 HTML 中一部电影的结构:

比斯瓦纳特

您可以进一步使用刮取的表。

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)     

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章