2

I have following code:

    from requests_html import HTMLSession()
    session = HTMLSession()

    response = session.get(url)
    response.html.render()  # <- causes error
    page_soup = soup(response.html.html, "html.parser")
    response.close()

which I'm trying to parse website with JS. Independently of which website I tried to render i get following error on Ubuntu:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/project1/project1_venv/lib/python3.8/site-packages/requests_html.py", line 586, in render
    self.browser = self.session.browser  # Automatically create a event loop and browser
  File "/home/project1/project1_venv/lib/python3.8/site-packages/requests_html.py", line 730, in browser
    self._browser = self.loop.run_until_complete(super().browser)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "/home/project1/project1_venv/lib/python3.8/site-packages/requests_html.py", line 714, in browser
    self._browser = await pyppeteer.launch(ignoreHTTPSErrors=not(self.verify), headless=True, args=self.__browser_args)
  File "/home/project1/project1_venv/lib/python3.8/site-packages/pyppeteer/launcher.py", line 306, in launch
    return await Launcher(options, **kwargs).launch()
  File "/home/project1/project1_venv/lib/python3.8/site-packages/pyppeteer/launcher.py", line 167, in launch
    self.browserWSEndpoint = get_ws_endpoint(self.url)
  File "/home/project1/project1_venv/lib/python3.8/site-packages/pyppeteer/launcher.py", line 226, in get_ws_endpoint
    raise BrowserError('Browser closed unexpectedly:\n')
pyppeteer.errors.BrowserError: Browser closed unexpectedly:

When I run the same code on my local computer with Windows 10 everything works fine.

In both environments the same versions of library:

requests-html==0.10.0

But on windows I have Python 3.7.2 and on Linux server Python 3.8.6. It's problem? In both environments I using venvs.

I have installed chromium on Ubuntu.

1
  • It seems that chromium needs some lib to run headlessly, maybe this and this can help. Commented Jun 30, 2021 at 9:57

2 Answers 2

4

I faced the same issue. The resolution which helped me I found on: https://techoverflow.net/2020/09/29/how-to-fix-pyppeteer-pyppeteer-errors-browsererror-browser-closed-unexpectedly/ . I executed the following command:

apt install -y gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

Now it works without any problem.

Sign up to request clarification or add additional context in comments.

Comments

-1

I face same issue on windows working fine while on Ubuntu show error for render()

when I remove it from code on windows then page not load properly and show error

while on ubuntu works fine. I think on ubuntu no need of including render().

Remove render() from code and try on it .

Hope it will work.

Thanks!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.