forked from jjlopez/descargar-cfdi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLForm.py
26 lines (21 loc) · 795 Bytes
/
HTMLForm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import lxml.html
class HTMLForm:
def __init__(self, htmlSource, xpathForm):
self.xpathForm = xpathForm
self.htmlSource = htmlSource
def getFormValues(self):
inputValues = self.readInputValues()
selectValues = self.readSelectValues()
values=inputValues.copy()
values.update(selectValues)
return values
def readInputValues(self):
return self.readAndGetValues("input")
def readSelectValues(self):
return self.readAndGetValues("select")
def readAndGetValues(self, element):
document=lxml.html.fromstring(self.htmlSource)
inputValues = {}
for input in document.xpath("//"+self.xpathForm+"/"+element):
inputValues[input.name] = input.value
return inputValues;