Код: Выделить всё
r = requests.get("https://en.wikipedia.org/wiki/Toy_Story_3")
soup = bs(r.content)
contents =soup.prettify()
info_box = soup.find(class_="infobox vevent")
info_rows = info_box.find_all("tr")
movie_info = {}
for index, row in enumerate(info_rows):
if index == 0:
movie_info['title'] = row.find("th").get_text()
elif index == 1:
continue
else:
content_key = row.find("th").get_text()
content_value =[row_data.get_text() for row_data in row.find("td").find_all("li")]
movie_info[content_key] = content_value
movie_info`
Код: Выделить всё
`{'title': 'Toy Story 3',
'Directed by': [],
'Screenplay by': [],
'Story by': ['John Lasseter', 'Andrew Stanton', 'Lee Unkrich'],
'Produced by': [],
'Starring': ['Tom Hanks',
'Tim Allen',
'Joan Cusack',
'Don Rickles',
'Wallace Shawn',
'John Ratzenberger',
'Estelle Harris',
'Ned Beatty',
'Michael Keaton',
'Jodi Benson',
'John Morris'],
'Cinematography': ['Jeremy Lasky', 'Kim White'],...}
Код: Выделить всё
Toy Story 3
Screenplay byMichael Arndt
Story by
.mw-parser-output .plainlist ol,.mw-parser-output .plainlist ul{line-height:inherit;list-style:none;margin:0;padding:0}.mw-parser-output .plainlist ol li,.mw-parser-output .plainlist ul li{margin-bottom:0}
[list]
[*]John Lasseter
[*]Andrew Stanton
[*]Lee Unkrich
[/list]
Produced byDarla K. Anderson
Starring
[list][*][url=/wiki/Tom_Hanks]Tom Hanks[/url]
[*][url=/wiki/Tim_Allen]Tim Allen[/url]
[*][url=/wiki/Joan_Cusack]Joan Cusack[/url]
[*][url=/wiki/Don_Rickles]Don Rickles[/url]
[*][url=/wiki/Wallace_Shawn]Wallace Shawn[/url]
[*][url=/wiki/John_Ratzenberger]John Ratzenberger[/url]
[*][url=/wiki/Estelle_Harris]Estelle Harris[/url]
[*][url=/wiki/Ned_Beatty]Ned Beatty[/url]
[*][url=/wiki/Michael_Keaton]Michael Keaton[/url]
[*][url=/wiki/Jodi_Benson]Jodi Benson[/url]
[*][url=/wiki/John_Morris_(American_actor)]John Morris[/url][/list]
.... more html code here
Подробнее здесь: https://stackoverflow.com/questions/790 ... t-will-tra