Как разобрать википедию редактировать данные с питона? - PullRequest
0 голосов
/ 07 мая 2019

Я пытаюсь проанализировать историю редактирования XML-файла Википедии с помощью xml.etree.ElementTree и создать кадр данных со столбцами, содержащими следующую информацию: (revision / id, revision / timestamp, revision / contributor / username, revision/ contributor / id, редакция / комментарий, редакция / текст).

Я новичок в Python, поэтому я пытался найти ресурсы для этого в Интернете, но не нашел ничего, что соответствовало бы тому, что мне нужно.Я пытаюсь отредактировать найденную здесь функцию ... https://robertopreste.com/blog/parse-xml-into-dataframe ..., чтобы выполнить работу.Однако функция не подходит для извлечения данных, вложенных в несколько уровней.

import pandas as pd
import xml.etree.ElementTree as et


def parse_XML(xml_file, df_cols):         
    xtree = et.parse(xml_file)
    xroot = xtree.getroot()
    out_df = pd.DataFrame(columns = df_cols)    
    for node in xroot: 
        res = []
        res.append(node.find(df_cols[0]))
        for el in df_cols[1:]: 
            if node is not None and node.find(el) is not None:
                res.append(node.find(el).text)
            else: 
                res.append(None)
        out_df = out_df.append(pd.Series(res, index = df_cols), ignore_index = True)        

    return out_df

parse_XML(wiki_url,["timestamp","contributor","comment","text"])

Вот как выглядит XML:

  <page>
    <title>Fight Club</title>
    <ns>0</ns>
    <id>1009041</id>
    <revision>
      <id>6128066</id>
      <timestamp>2004-09-22T20:36:20Z</timestamp>
      <contributor>
        <username>LGagnon</username>
        <id>31951</id>
      </contributor>
      <comment>started page with info migrated from [[Fight Club]]; more to be migrated later</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text xml:space="preserve" bytes="2122">[[Image:Fight Club DVD.jpg|150px|thumbnail|Fight Club DVD]]

'''''Fight Club''''' ([[1999]]) is a film based on the novel ''[[Fight Club]]'' by [[Chuck Palahniuk]]. It was directed by [[David Fincher]] and starred [[Brad Pitt]], [[Edward Norton]], and [[Helena Bonham Carter]]. Also featured in it is an original soundtrack by the [[Dust Brothers]]. As of June 23, 2004 ''Fight Club'' is in development as a musical, developed by Palahniuk and Fincher. A video game based on the film is also planned to be released in October of 2004.

==Awards==
The film won the following awards:
* the 2000 Empire Award (UK) for Best British Actress (Helena Bonham Carter)
* the 2001 Online Film Critics Society Awards for Best DVD, Best DVD Commentary, and Best DVD Special Features

It was also nominated for the following awards:
* the 2000 [[Academy Award]] for Best Effects, Sound Effects Editing
* the 2000 Blockbuster Entertainment Award for Favorite Action Team (Brad Pitt &amp; Edward Norton)
* the 2000 Brit Award for Best Soundtrack
* the 2000 Costume Designers Guild Award for Excellence for Costume Design for Film - Contemporary
* the 2000 Sierra Award from the Las Vegas Film Critics Society Awards for Best DVD and Best Editing
* the 2000 MTV Movie Award for Best Fight (Edward Norton vs himself)
* the 2000 Golden Reel Award from the Motion Picture Sound Editors, USA for Best Sound Editing - Effects &amp; Foley
* the 2000 Online Film Critics Society Awards for Best Actor (Edward Norton), Best Director, Best Film, Best Film Editing, and Best Screenplay, Adapted
* the 2000 Political Film Society Award for Democracy

==Technical data (film)==
* writing credits: Chuck Palahniuk (novel), Jim Uhls (screenplay)
* runtime: 139 minutes
* sound: [[DTS]] / Dolby EX 6.1
* aspect ratio: 2.35 : 1
* release date: October 6, 1999 (USA)
* budget: $63,000,000
* MPAA rating: R

==See also==
*[[1990s in film]]
*[[1999 in film]]
*[[Generation X]]

==External links==
{{wikiquote}}
*[http://us.imdb.com/Title?0137523 IMDb entry for ''Fight Club'']

[[Category:1999 films]]
[[Category:Cult films]]
[[de:Fight Club]][[pt:Clube de Combate]]</text>
      <sha1>3lebh5bkxywcrfrjpphyd6cd02qp2f9</sha1>
    </revision>
    <revision>
      <id>6128468</id>
      <parentid>6128066</parentid>
      <timestamp>2004-09-24T20:25:34Z</timestamp>
      <contributor>
        <username>LGagnon</username>
        <id>31951</id>
      </contributor>
      <comment>[[Category:Chuck Palahniuk]]</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text xml:space="preserve" bytes="2151">[[Image:Fight Club DVD.jpg|150px|thumbnail|Fight Club DVD]]

'''''Fight Club''''' ([[1999]]) is a film based on the novel ''[[Fight Club]]'' by [[Chuck Palahniuk]]. It was directed by [[David Fincher]] and starred [[Brad Pitt]], [[Edward Norton]], and [[Helena Bonham Carter]]. Also featured in it is an original soundtrack by the [[Dust Brothers]]. As of June 23, 2004 ''Fight Club'' is in development as a musical, developed by Palahniuk and Fincher. A video game based on the film is also planned to be released in October of 2004.

==Awards==
The film won the following awards:
* the 2000 Empire Award (UK) for Best British Actress (Helena Bonham Carter)
* the 2001 Online Film Critics Society Awards for Best DVD, Best DVD Commentary, and Best DVD Special Features

It was also nominated for the following awards:
* the 2000 [[Academy Award]] for Best Effects, Sound Effects Editing
* the 2000 Blockbuster Entertainment Award for Favorite Action Team (Brad Pitt &amp; Edward Norton)
* the 2000 Brit Award for Best Soundtrack
* the 2000 Costume Designers Guild Award for Excellence for Costume Design for Film - Contemporary
* the 2000 Sierra Award from the Las Vegas Film Critics Society Awards for Best DVD and Best Editing
* the 2000 MTV Movie Award for Best Fight (Edward Norton vs himself)
* the 2000 Golden Reel Award from the Motion Picture Sound Editors, USA for Best Sound Editing - Effects &amp; Foley
* the 2000 Online Film Critics Society Awards for Best Actor (Edward Norton), Best Director, Best Film, Best Film Editing, and Best Screenplay, Adapted
* the 2000 Political Film Society Award for Democracy

==Technical data (film)==
* writing credits: Chuck Palahniuk (novel), Jim Uhls (screenplay)
* runtime: 139 minutes
* sound: [[DTS]] / Dolby EX 6.1
* aspect ratio: 2.35 : 1
* release date: October 6, 1999 (USA)
* budget: $63,000,000
* MPAA rating: R

==See also==
*[[1990s in film]]
*[[1999 in film]]
*[[Generation X]]

==External links==
{{wikiquote}}
*[http://us.imdb.com/Title?0137523 IMDb entry for ''Fight Club'']

[[Category:1999 films]]
[[Category:Chuck Palahniuk]]
[[Category:Cult films]]
[[de:Fight Club]][[pt:Clube de Combate]]</text>
      <sha1>jrrauydgl1lwexglixno78buqiwt0mn</sha1>
    </revision>
    <revision>
      <id>6128588</id>
      <parentid>6128468</parentid>
      <timestamp>2004-09-24T20:49:04Z</timestamp>
      <contributor>
        <username>LGagnon</username>
        <id>31951</id>
      </contributor>
      <comment>migrated plot details from [[Fight Club]]</comment>
      <model>wikitext</model>
      <format>text/x-wiki</format>
      <text xml:space="preserve" bytes="3144">[[Image:Fight Club DVD.jpg|150px|thumbnail|Fight Club DVD]]

'''''Fight Club''''' ([[1999]]) is a film based on the novel ''[[Fight Club]]'' by [[Chuck Palahniuk]]. It was directed by [[David Fincher]] and starred [[Brad Pitt]], [[Edward Norton]], and [[Helena Bonham Carter]]. Also featured in it is an original soundtrack by the [[Dust Brothers]]. As of June 23, 2004 ''Fight Club'' is in development as a musical, developed by Palahniuk and Fincher. A video game based on the film is also planned to be released in October of 2004. 

==Plot==
[[Image:brad_pitt6.jpg|150px|right|Brad Pitt as Tyler Durden with Edward Norton as the Narrator]]

Though the plot is mostly similar to the novel, some significant changes have been made. The originally nameless narrator is now named in publicity for the movie as "Jack" (although his real name, like in the novel, is never mentioned in the dialog). Tyler Durden is now a soap salesman instead of a beach artist. The narrator is now not entirely aware of what Tyler is doing with Project Mayhem and thus becomes increasingly uncomfortable with the increasing destructiveness of their activities, rather than being partially in control of it as in the book. Tyler is now the result of the narrator's repressed anger towards his modern life instead of his feelings for Marla.

[[Image:Marla_Singer_and_Jack.jpg.jpg |150px|right|Helena Bonham Carter as Marla Singer with the Narrator]]
==Awards==
The film won the following awards:
* the 2000 Empire Award (UK) for Best British Actress (Helena Bonham Carter)
* the 2001 Online Film Critics Society Awards for Best DVD, Best DVD Commentary, and Best DVD Special Features

[[Image:Robert_Pulson_with_Jack.jpg.jpg|150px|right|Meat Loaf as Robert Paulson with the Narrator]]
It was also nominated for the following awards:
* the 2000 [[Academy Award]] for Best Effects, Sound Effects Editing
* the 2000 Blockbuster Entertainment Award for Favorite Action Team (Brad Pitt &amp; Edward Norton)
* the 2000 Brit Award for Best Soundtrack
* the 2000 Costume Designers Guild Award for Excellence for Costume Design for Film - Contemporary
* the 2000 Sierra Award from the Las Vegas Film Critics Society Awards for Best DVD and Best Editing
* the 2000 MTV Movie Award for Best Fight (Edward Norton vs himself)
* the 2000 Golden Reel Award from the Motion Picture Sound Editors, USA for Best Sound Editing - Effects &amp; Foley
* the 2000 Online Film Critics Society Awards for Best Actor (Edward Norton), Best Director, Best Film, Best Film Editing, and Best Screenplay, Adapted
* the 2000 Political Film Society Award for Democracy

==Technical data (film)==
* writing credits: Chuck Palahniuk (novel), Jim Uhls (screenplay)
* runtime: 139 minutes
* sound: [[DTS]] / Dolby EX 6.1
* aspect ratio: 2.35 : 1
* release date: October 6, 1999 (USA)
* budget: $63,000,000
* MPAA rating: R

==See also==
*[[1990s in film]]
*[[1999 in film]]
*[[Generation X]]

==External links==
{{wikiquote}}
*[http://us.imdb.com/Title?0137523 IMDb entry for ''Fight Club'']

[[Category:1999 films]]
[[Category:Chuck Palahniuk]]
[[Category:Cult films]]
[[de:Fight Club]][[pt:Clube de Combate]]</text>
      <sha1>82904465ye6r5u1pkvcqyloh3ass7il</sha1>
    </revision>
</page>

Кто-нибудь знает, как редактировать формулудля того, чтобы получить то, что мне нужно или любой другой метод для этого?

...