Skip to content

Instantly share code, notes, and snippets.

@gregelin
Last active September 28, 2017 19:00
Show Gist options
  • Select an option

  • Save gregelin/08661858f6a2eeda2776 to your computer and use it in GitHub Desktop.

Select an option

Save gregelin/08661858f6a2eeda2776 to your computer and use it in GitHub Desktop.
Notes on parsing MS word docx footnotes

Parsing MS Word .docx Footnotes

Links

Snippets

  • soup = BeautifulSoup(open("filename").read())
  • import readline; print '\n'.join([str(readline.get_history_item(i)) for i in range(readline.get_current_history_length())])
  • print history of python shell
# find history of python shell commands
import readline
for i in range(readline.get_current_history_length()):
    print readline.get_history_item(i)

# find history of python shell commands, in one line
import readline; print '\n'.join([str(readline.get_history_item(i)) for i in range(readline.get_current_history_length())])

Snippet to get text from all footnotes

from BeautifulSoup import BeautifulSoup
import urllib2
open urllib2.open()
docurl = "https://raw.githubusercontent.com/adelevie/open-internet-order-footnotes/master/word/footnotes.xml"
page = urllib2.urlopen(docurl)
soup = BeautifulSoup(page)
print soup.prettify()

docurl = "https://raw.githubusercontent.com/adelevie/open-internet-order-footnotes/master/word/footnotes.xml"
page = urllib2.urlopen(docurl)
soup = BeautifulSoup(page)
footnotes = soup.findAll('w:footnote')
for f in footnotes:
  print f['w:id']
  f.text

# Since we have name spaces, we need to use 'findAll' instead of dot notation.
footnotes = soup.findAll('w:footnote')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment