Open
Description
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这部分,非常感谢作者,期待您的回复
Metadata
Metadata
Assignees
Labels
No labels