Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pyppeteer能否更换为Playwright? #28

Open
fresh-hands opened this issue Jan 12, 2025 · 1 comment
Open

Pyppeteer能否更换为Playwright? #28

fresh-hands opened this issue Jan 12, 2025 · 1 comment

Comments

@fresh-hands
Copy link

fresh-hands commented Jan 12, 2025

Pyppeteer Attention: This repo is unmaintained and has been outside of minor changes for a long time. Please consider playwright-python as an alternative.
Pyppeteer已经快一年没有新的commit了,而且其自动配置浏览器很麻烦。而我使用playwright自动配置浏览器很容易就成功了,并且项目非常活跃。
由于水平有限,我只会自己使用以下命令来配置,供大家参考
pipenv install chardet playwright
pipenv run python -m playwright install
pipenv run playwright install-deps
Python函数代码

from playwright.async_api import async_playwright
from parsel import Selector
async def fetch_by_playwright(url: str):
    try:
        async with async_playwright() as p:
            browser = await p.chromium.launch(headless=True)  
            page = await browser.new_page() 
            await page.goto(url)
            html_content = await page.content()
            await browser.close()
            return Selector(text=html_content)
    except Exception as e:
        print(f'[Err] {e}')
        return None

希望在新版本中作者能优化Pyppeteer这部分,非常感谢作者,期待您的回复

@KeithW0726
Copy link

KeithW0726 commented Feb 28, 2025

+1 Pyppeteer 基本跟不上,js原版的很多特性了。

Playwright是MS亲孩子,特性和支持是非常地好

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants