【转】pyppeteer+chromium手动安装Mac版本
Mac端安装
首先确保pyppeteer安装完成
找到pyppeteer安装路径
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer
找到 chromium_downloader.py文件
执行并获取需要的chromium编号和文件路径
在文件中增添如下一行:
print(chromium_executable())
执行文件 python3 chromium_downloader.py
输出结果如下:
MacBookPro:pyppeteer baoshan$ python3 chromium_downloader.py /Users/baoshan/Library/Application Support/pyppeteer/local-chromium/588429/chrome-mac/Chromium.app/Contents/MacOS/Chromium
说明下载Mac版588429版本
下载地址:https://npm.taobao.org/mirrors/chromium-browser-snapshots/
将下载的Chromium.app按照上面的文件路径放好,
再执行如下程序,不会报错了:
import asyncio from pyppeteer import launch from pyquery import PyQuery as pq async def main(): browser = await launch() page = await browser.newPage() await page.goto('https://dynamic2.scrape.center/') await page.waitForSelector('.item .name') doc = pq(await page.content()) names = [item.text() for item in doc('.item .name').items()] print('Names:', names) await browser.close() asyncio.get_event_loop().run_until_complete(main())
输出结果如下:
Names: ['霸王别姬 - Farewell My Concubine', '这个杀手不太冷 - Léon', '肖申克的救赎 - The Shawshank Redemption', '泰坦尼克号 - Titanic', '罗马假日 - Roman Holiday', '唐伯虎点秋香 - Flirting Scholar', '乱世佳人 - Gone with the Wind', '喜剧之王 - The King of Comedy', '楚门的世界 - The Truman Show', '狮子王 - The Lion King']
windows安装参考:win10 https://www.cnblogs.com/kindvampire/p/13088636.html