requests-html
requests-html copied to clipboard
Updates to docs so users can know how to run in Jupyter
Thank you for this package!
Users who try to run async in Jupyter get an error. Trace is below. A solution is to install nest_asyncio
https://github.com/erdewit/nest_asyncio
pip install nest_asyncio
import nest_asyncio
nest_asyncio.apply()
Also, the Python 2.0 countdown clock is no longer counting down, so a different example might be preferable in the docs. :)
Error trace from running in Jupyter notebook. I was using Jupyter Lab on a Mac with Chrome.
RuntimeError Traceback (most recent call last)
~/miniconda3/lib/python3.7/site-packages/requests_html.py in run(self, *coros) 772 asyncio.ensure_future(coro()) for coro in coros 773 ] --> 774 done, _ = self.loop.run_until_complete(asyncio.wait(tasks)) 775 return [t.result() for t in done]
~/miniconda3/lib/python3.7/asyncio/base_events.py in run_until_complete(self, future) 568 future.add_done_callback(_run_until_complete_cb) 569 try: --> 570 self.run_forever() 571 except: 572 if new_task and future.done() and not future.cancelled():
~/miniconda3/lib/python3.7/asyncio/base_events.py in run_forever(self) 523 self._check_closed() 524 if self.is_running(): --> 525 raise RuntimeError('This event loop is already running') 526 if events._get_running_loop() is not None: 527 raise RuntimeError(
RuntimeError: This event loop is already running
I don't think it "works", even if in some cases it does. For example, this snippet hangs:
import nest_asyncio
from requests_html import AsyncHTMLSession
asession = AsyncHTMLSession()
nest_asyncio.apply(asession.loop)
async def get_pythonorg():
site = await asession.get('https://python.org/')
await site.html.arender(keep_page=True)
return site
web = asession.run(get_pythonorg)
print(web)
I don't think it "works", even if in some cases it does. For example, this snippet hangs:
import nest_asyncio from requests_html import AsyncHTMLSession asession = AsyncHTMLSession() nest_asyncio.apply(asession.loop) async def get_pythonorg(): site = await asession.get('https://python.org/') await site.html.arender(keep_page=True) return site web = asession.run(get_pythonorg) print(web)
I try for this code but I find error like (from requests-html SyntaxError: invalid syntax)
import nest_asyncio from requests-html import AsyncHTMLSession asession = AsyncHTMLSession() nest_asyncio.apply(asession.loop)
async def get_pythonorg(): site = await asession.get('https://python.org/') await site.html.arender(keep_page=True) return site
web = asession.run(get_pythonorg) print(web)