Update requests_html.py

e.g. to add a proxy setting
usage: s=Session(browser_args=['--no-sandbox', '--proxy-server=127.0.0.1:9876'])
@see: https://github.com/GoogleChrome/puppeteer/issues/336
This commit is contained in:
Martin Rotwang
2018-06-05 12:39:46 +02:00
committed by GitHub
parent c59480bf15
commit 96dbba8fbd
+4 -2
View File
@@ -645,7 +645,7 @@ class HTMLSession(requests.Session):
amongst other things.
"""
def __init__(self, mock_browser=True):
def __init__(self, mock_browser=True, browser_args=['--no-sandbox']):
super(HTMLSession, self).__init__()
# Mock a web browser's user agent.
@@ -654,6 +654,8 @@ class HTMLSession(requests.Session):
self.hooks = {'response': self._handle_response}
self.__browser_args = browser_args
@staticmethod
def _handle_response(response, **kwargs) -> HTMLResponse:
"""Requests HTTP Response handler. Attaches .html property to
@@ -677,7 +679,7 @@ class HTMLSession(requests.Session):
def browser(self):
if not hasattr(self, "_browser"):
self.loop = asyncio.get_event_loop()
self._browser = self.loop.run_until_complete(pyppeteer.launch(headless=True, args=['--no-sandbox']))
self._browser = self.loop.run_until_complete(pyppeteer.launch(headless=True, args=self.__browser_args))
return self._browser
def close(self):