Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except splunk.ResourceNotFound:
cherrypy.response.status = 202
return self.render_error_json(_("Proxy server information could not be obtained"))
# Scrape the page
result = web_scraper.scrape_page(url, selector, **kw)
except FieldValidationException as e:
cherrypy.response.status = 220
return self.render_error_json(_(str(e)))
except ServerNotFoundError as e:
cherrypy.response.status = 220
return self.render_error_json(_(str(e)))
except (SelectorError, SelectorSyntaxError, ExpressionError):
cherrypy.response.status = 220
return self.render_error_json(_("Selector is invalid. "))
except LoginFormNotFound:
cherrypy.response.status = 220
return self.render_error_json("Login form was not found")
except FormAuthenticationFailed:
cherrypy.response.status = 220
return self.render_error_json("Form authentication failed")
except Exception as e:
cherrypy.response.status = 500
logger.exception("Error generated during execution")
return self.render_error_json(_(str(e)))
web_scraper.set_proxy(proxy_type, proxy_server, proxy_port, proxy_user, proxy_password)
except ResourceNotFound:
return self.render_error_json("Proxy server information could not be obtained", 202)
# Scrape the page
result = web_scraper.scrape_page(url, selector, **kw)
except FieldValidationException as e:
return self.render_error_json(str(e), 220)
except ServerNotFoundError as e:
return self.render_error_json(str(e), 220)
except (SelectorError, SelectorSyntaxError, ExpressionError):
return self.render_error_json("Selector is invalid. ", 220)
except LoginFormNotFound:
return self.render_error_json("Login form was not found", 220)
except FormAuthenticationFailed:
return self.render_error_json("Form authentication failed", 220)
except Exception as e:
logger.exception("Error generated during execution")
return self.render_error_json(str(e), 500)
# Return the information
if 'include_first_result_only' in kwargs:
return self.render_json(result[0])
else:
"""
from __future__ import absolute_import
from . import etree
try:
import cssselect as external_cssselect
except ImportError:
raise ImportError(
'cssselect does not seem to be installed. '
'See http://packages.python.org/cssselect/')
SelectorSyntaxError = external_cssselect.SelectorSyntaxError
ExpressionError = external_cssselect.ExpressionError
SelectorError = external_cssselect.SelectorError
__all__ = ['SelectorSyntaxError', 'ExpressionError', 'SelectorError',
'CSSSelector']
class LxmlTranslator(external_cssselect.GenericTranslator):
"""
A custom CSS selector to XPath translator with lxml-specific extensions.
"""
def xpath_contains_function(self, xpath, function):
# Defined there, removed in later drafts:
# http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors
if function.argument_types() not in (['STRING'], ['IDENT']):
raise ExpressionError(
"Expected a single string or ident for :contains(), got %r"
"""
from __future__ import absolute_import
from . import etree
try:
import cssselect as external_cssselect
except ImportError:
raise ImportError(
'cssselect does not seem to be installed. '
'See http://packages.python.org/cssselect/')
SelectorSyntaxError = external_cssselect.SelectorSyntaxError
ExpressionError = external_cssselect.ExpressionError
SelectorError = external_cssselect.SelectorError
__all__ = ['SelectorSyntaxError', 'ExpressionError', 'SelectorError',
'CSSSelector']
class LxmlTranslator(external_cssselect.GenericTranslator):
"""
A custom CSS selector to XPath translator with lxml-specific extensions.
"""
def xpath_contains_function(self, xpath, function):
# Defined there, removed in later drafts:
# http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#content-selectors
if function.argument_types() not in (['STRING'], ['IDENT']):
raise ExpressionError(
"Expected a single string or ident for :contains(), got %r"