Python ';协同程序';对象没有属性get | | pyppeteer
在python中,使用pyppeteer,我打开一个网页,并在其控制台中运行一个JS脚本,试图捕获变量中的结果,但我得到以下错误Python ';协同程序';对象没有属性get | | pyppeteer,python,node.js,puppeteer,google-chrome-headless,pyppeteer,Python,Node.js,Puppeteer,Google Chrome Headless,Pyppeteer,在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)
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
有人能建议如何解决这个问题吗?需要更多的上下文 您的错误没有引用脚本中的任何代码,但存在对不可见对象的引用 听起来你要么错过了某个地方的“等待”,要么你需要给aysnc工厂打电话 一旦我知道更多,我可以帮你
我还建议升级到3.8,因为Asyncio对python来说是最近才出现的,它不会有什么坏处。
AttributeError:“coroutine”对象没有属性“get”
/home/naruto/anaconda3/lib/python3.7/pathlib.py:704:RuntimeWarning:coroutine'hmm'从未被等待过
这意味着你要打电话
hmm(请求).get()
相反
r=wait-hmm(请求)
r、 get()
在您的代码中的某个地方,围绕此函数编写代码