gpt4 book ai didi

python - “coroutine”对象没有属性 get || pyppeteer

转载 作者:太空宇宙 更新时间:2023-11-03 19:49:23 27 4
gpt4 key购买 nike

在Python中,使用pyppeteer,我打开一个网页在其控制台中运行JS脚本并尝试捕获结果在变量中,但我收到以下错误。

Traceback (most recent call last):
File "/home/ndaruto/anaconda3/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/naruto/anaconda3/lib/python3.7/site-packages/django/utils/deprecation.py", line 96, in __call__
response = self.process_response(request, response)
File "/home/naruto/anaconda3/lib/python3.7/site-packages/django/middleware/clickjacking.py", line 26, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'coroutine' object has no attribute 'get'
/home/naruto/anaconda3/lib/python3.7/pathlib.py:704: RuntimeWarning: coroutine 'hmm' was never awaited


return self._str
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

下面是 python 代码:-

async def hmm(request):
browser = await launch()
page = await browser.newPage()
await page.goto('http://jobs.chegg.com')
ans = await page.evaluate('''() => {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/axe-core/3.1.2/axe.min.js';
document.head.appendChild(script);
setTimeout(function(){
axe.run(document, {
runOnly: {
type: "tag",
values: ["wcag2a", "wcag2aa", "best-practice"]
},
"rules": {
"skip-link": { enabled: false }
}
}, function(err, results) {
if (err) throw err;
console.log(results);
});
}, 1000);
}''')
print("ANS IS", ans)
return 1

有人可以建议如何解决这个问题吗?

最佳答案

AttributeError:“coroutine”对象没有属性“get”
/home/naruto/anaconda3/lib/python3.7/pathlib.py:704:RuntimeWarning:从未等待协程“hmm”
这意味着你打电话嗯(请求).get()
相反
r = 等待嗯(请求)
r.get()

在你的代码中围绕这个函数的某个地方

关于python - “coroutine”对象没有属性 get || pyppeteer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59927874/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com