参考:https://blog.csdn.net/weixin_41822224/article/details/103719863
必须增加在多线程中才能运行
"handleSIGINT": False,
"handleSIGTERM": False,
"handleSIGHUP": False
import asyncio
from pyppeteer import launch
import time
from app.libs.thread.own_thread import OwnThread
is_mobile_browser = False
_defaultViewport = {
"width": 375,
"height": 668,
"isMobile": True,
"hasTouch": True,
} if is_mobile_browser else {
"width": 998,
"height": 800,
"isMobile": False,
"hasTouch": False,
}
async def temp_func():
browser = await launch(
options={
'headless': False,
'args': ['--no-sandbox'],
"defaultViewport": _defaultViewport,
"handleSIGINT": False,
"handleSIGTERM": False,
"handleSIGHUP": False
})
page = await browser.newPage()
await page.setJavaScriptEnabled(enabled=True)
await page.goto('www.baidu.com')
ele = await page.J(".main")
print(await (await ele.getProperty("src")).jsonValue())
time.sleep(30)
await browser.close()
OwnThread(lambda: asyncio.run(temp_func())).start()
print("aaaa")