J000291 #513 added, fixes to py file (added how to)

This commit is contained in:
makecakenotwar97@gmail.com
2013-08-19 17:24:51 -04:00
parent c56a73ac04
commit f68458f663
2 changed files with 205 additions and 2 deletions

View File

@@ -1,3 +1,23 @@
'''
HOW TO USE:
Copy this file to a separate location (so as not to hide random files
to github)
Create a folder named "input" in the same location
Copy the section of the HTML containing the form options that you
want to extract (does not have to be exact, you can even copy and paste
the entire HTML source code if you want, only there is less chance for
errors if you only copy/paste the section containing the form)
Paste into a text file (NOT word) and save in the "input" folder.
Run the .py file in python 3.3, and copy/paste the resulting output.
It is recommended to check the output for any errors (if the attribute is
in single quotes you can change this in the regular expression below to
r'(?:<option.*?value\s*=\s*)(\'.*?\')'.
'''
import os
import re
@@ -6,7 +26,7 @@ YAMLselections = []
#compile regular expressions
select = re.compile(r'<select.*?</select>', re.DOTALL)
selectoptions = re.compile(r'(?:<option.*?value\s*=\s*)([\'\"].*?[\'\"])')
selectoptions = re.compile(r'(?:<option.*?value\s*=\s*)(\".*?\")')
for root,dirs,files in os.walk('.\input'):
for file in files:
@@ -17,7 +37,7 @@ for root,dirs,files in os.walk('.\input'):
options = re.findall(selectoptions, selector)
data = '------------\n' + file + '\n' + 'options:' + '\n'
for option in options:
data = data + " "
data = data + " "
data = data + "- " + option + '\n'
YAMLselections.append(data)
for x in YAMLselections: