feapder
feapder copied to clipboard
playwright方式报错
问题 运行示例test_playwright.py 报错playwright._impl._errors.Error: It looks like you are using Playwright Sync API inside the asyncio loop.\nPlease use the Async API instead.
python环境 conda python 3.10 feapder[render] 1.9.0
截图
代码
import time
from playwright.sync_api import Page
import feapder
from feapder.utils.webdriver import PlaywrightDriver
class TestPlaywright(feapder.AirSpider):
__custom_setting__ = dict(
RENDER_DOWNLOADER="feapder.network.downloader.PlaywrightDownloader",
)
def start_requests(self):
yield feapder.Request("https://www.baidu.com", render=True)
def parse(self, reqeust, response):
driver: PlaywrightDriver = response.driver
page: Page = driver.page
page.type("#kw", "feapder")
page.click("#su")
page.wait_for_load_state("networkidle")
time.sleep(1)
html = page.content()
response.text = html # 使response加载最新的页面
for data_container in response.xpath("//div[@class='c-container']"):
print(data_container.xpath("string(.//h3)").extract_first())
if __name__ == "__main__":
TestPlaywright(thread_count=1).run()