在python中,使用pyppeteer,我正在打开一个网页和,在其控制台中运行JS脚本,并试图捕获变量e中的结果,但我得到了以下错误。
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有人能给我建议怎么解决这个问题吗?
发布于 2020-02-20 13:57:36
AttributeError: 'coroutine' object has no attribute 'get' /home/naruto/anaconda3/lib/python3.7/pathlib.py:704: RuntimeWarning: coroutine 'hmm' was never awaited --这意味着你叫hmm(request).get()
相反,
r = await hmm(request) r.get()
在您的代码中的某个地方围绕着这个函数
发布于 2020-02-10 19:57:51
需要更多的背景。
您的错误没有引用脚本中的任何代码,但是有对不可见对象的引用。
听起来你要么错过了某个地方的“等待”,要么你需要打电话给一家aysnc工厂。
一旦我知道得更多我就能帮上忙了。
我还建议将Asyncio升级到3.8,因为Asyncio对python来说是比较新的,它不会有什么坏处。
https://stackoverflow.com/questions/59927874
复制相似问题