Last active
June 7, 2019 04:48
-
-
Save hrsano645/5d62b97e542804c4a8fe57f941efb214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from pyppeteer import launch | |
from pathlib import Path | |
# ref:https://qiita.com/horikeso/items/69528c2b21ede15a56ee | |
download_path = Path("./download") | |
async def main(): | |
browser = await launch() | |
page = await browser.newPage() | |
await page._client.send( | |
"Page.setDownloadBehavior", {"behavior": "allow", "downloadPath": download_path} | |
) | |
await page.setViewport({"width": 1000, "height": 1000}) | |
await page.goto("https://www.google.co.jp/chrome/", {"waitUntil": "networkidle0"}) | |
await page.waitForSelector("#js-download-hero") | |
await page.click("#js-download-hero") | |
await page.click("#js-accept-install") | |
# DL中の監視 | |
filename = "" | |
while not filename or filename.endswith(".crdownload"): | |
# ファイルを見て監視する | |
watch_dir_list = list(download_path.glob("*")) | |
if watch_dir_list: | |
filename = str(watch_dir_list[0]) | |
print(filename) | |
await asyncio.sleep(1) | |
# 終了処理 | |
await browser.close() | |
asyncio.get_event_loop().run_until_complete(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment