У меня есть код Python, в котором я отправляю запрос на URL-адрес, а затем использую функцию рендеринга библиотеки requests_ html для рендеринга js бит возвращенного html и сохранения некоторых результатов из это.
Вот небольшой код
session = HTMLSession()
response = session.get(url)
response.html.render()
Он отлично работает на моем ноутбуке, но когда я загружаю его на Google Диск в виде файла .py и запускаю изнутри Google Colab, используя
!python3 my_script.py
возвращает ошибки в третьей строке. Вот ошибка:
response.html.render()
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 586, in render
self.browser = self.session.browser # Automatically create a event loop and browser
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 730, in browser
self._browser = self.loop.run_until_complete(super().browser)
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 714, in browser
self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 305, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 166, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 225, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "my_script.py", line 50, in <module>
response.html.render()
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 586, in render
self.browser = self.session.browser # Automatically create a event loop and browser
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 730, in browser
self._browser = self.loop.run_until_complete(super().browser)
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/usr/local/lib/python3.6/dist-packages/requests_html.py", line 714, in browser
self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 305, in launch
return await Launcher(options, **kwargs).launch()
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 166, in launch
self.browserWSEndpoint = get_ws_endpoint(self.url)
File "/usr/local/lib/python3.6/dist-packages/pyppeteer/launcher.py", line 225, in get_ws_endpoint
raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:
Возможно, это что-то, что Google настроил, чтобы избежать отправки веб-запросов от Colab, или это можно исправить?