python - 有人在 requests_html 中使用 arender() 吗?
问题描述
import asyncio
from requests_html import AsyncHTMLSession
URLS = [
'https://pythonprogramming.net/parsememcparseface/',
# ...
# ...
]
async def send_request(session, url):
r = await session.get(url)
# await r.html.arender(timeout=120)
return r
async def get_tasks(session, urls):
tasks = []
for url in urls:
tasks.append(
asyncio.create_task(send_request(session, url))
)
return tasks
async def main(urls):
asession = AsyncHTMLSession()
Tasks = await get_tasks(asession, urls)
await asession.close()
return await asyncio.gather(*Tasks)
req = asyncio.run(main(URLS)) # [<Response [200]>]
print(req[0].html.find("#yesnojs", first=True).text)
如果取消注释第 12 行(await r.html.arender(timeout=120))并运行代码结果是成功的,但最后会出现此错误
Look at you shinin! <--- Result
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "C:\Users\Shayan\AppData\Local\Programs\Python\Python39\lib\site-packages\pyppeteer\launcher.py", line 152, in _close_process
self._loop.run_until_complete(self.killChrome())
File "C:\Users\Shayan\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 617, in run_until_complete
self._check_closed()
File "C:\Users\Shayan\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 510, in _check_closed
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
sys:1: RuntimeWarning: coroutine 'Launcher.killChrome' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
你能建议另一种方式来呈现页面的 javascript 吗?
解决方案
推荐阅读
- python - Python:批量读取并发送 json
- c# - 如何在与数据库的连接中使用 IList
- c# - 如何在硒测试c#中实现while循环
- python - list_display 未在 ModelAdmin Django 中显示 email_verified 字段
- xml - 来自 sql 的 xml 元素
- jackson - 无法从 START_ARRAY 令牌中反序列化 java.util.LinkedHashMap 的实例
- android - moto g6(不是 moto G6 plus)是否支持谷歌 ARCore?
- sql - SQL Server Always Encrypted - 最大参数数
- javascript - 将所有图像文件从 node.js 发送到前端
- vagrant - 使用打包程序构建 Windows 2012R2 映像:内容类型无效