Skip to content

Instantly share code, notes, and snippets.

@chewxy
Created September 3, 2014 04:22
Show Gist options
  • Save chewxy/f15bb13a83469cacdc19 to your computer and use it in GitHub Desktop.
Save chewxy/f15bb13a83469cacdc19 to your computer and use it in GitHub Desktop.
Gets the EBNF from the ECMAScript 5.1 spec
from bs4 import BeautifulSoup
import requests
r = requests.get('http://www.ecma-international.org/ecma-262/5.1/')
soup = BeautifulSoup(r.text)
sections = ('sec-A.1', 'sec-A.2', 'sec-A.3', 'sec-A.4', 'sec-A.5')
appendix = []
for s in sections:
appendix.append(soup.find(id=s))
bnf = []
for a in appendix:
divs = a.find_all('div', class_='gp')
bnf += [x.get_text() for x in divs]
bnftxt = '\n'.join([x.strip('\n').replace('\n', ' ') for x in bnf])
with open('jsout.txt', 'w') as f:
f.write(bnftxt.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment