mirror of
https://github.com/kennethreitz/requests-html.git
synced 2026-06-05 23:00:20 +00:00
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:
+4
-2
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user