Allow forcing a Page content encoding
This commit is contained in:
parent
e01b39c8d2
commit
82f47bff88
1 changed files with 14 additions and 2 deletions
|
|
@ -517,9 +517,15 @@ class JsonPage(BasePage):
|
||||||
|
|
||||||
|
|
||||||
class XMLPage(BasePage):
|
class XMLPage(BasePage):
|
||||||
|
ENCODING = None
|
||||||
|
"""
|
||||||
|
Force a page encoding.
|
||||||
|
It is recommended to use None for autodetection.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, browser, response, *args, **kwargs):
|
def __init__(self, browser, response, *args, **kwargs):
|
||||||
super(XMLPage, self).__init__(browser, response, *args, **kwargs)
|
super(XMLPage, self).__init__(browser, response, *args, **kwargs)
|
||||||
parser = etree.XMLParser(encoding=response.encoding)
|
parser = etree.XMLParser(encoding=self.ENCODING or response.encoding)
|
||||||
self.doc = etree.parse(StringIO(response.content), parser)
|
self.doc = etree.parse(StringIO(response.content), parser)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -535,9 +541,15 @@ class HTMLPage(BasePage):
|
||||||
"""
|
"""
|
||||||
FORM_CLASS = Form
|
FORM_CLASS = Form
|
||||||
|
|
||||||
|
ENCODING = None
|
||||||
|
"""
|
||||||
|
Force a page encoding.
|
||||||
|
It is recommended to use None for autodetection.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, browser, response, *args, **kwargs):
|
def __init__(self, browser, response, *args, **kwargs):
|
||||||
super(HTMLPage, self).__init__(browser, response, *args, **kwargs)
|
super(HTMLPage, self).__init__(browser, response, *args, **kwargs)
|
||||||
parser = html.HTMLParser(encoding=response.encoding)
|
parser = html.HTMLParser(encoding=self.ENCODING or response.encoding)
|
||||||
self.doc = html.parse(StringIO(response.content), parser)
|
self.doc = html.parse(StringIO(response.content), parser)
|
||||||
|
|
||||||
def get_form(self, xpath='//form', name=None, nr=None):
|
def get_form(self, xpath='//form', name=None, nr=None):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue