Skip to content

Instantly share code, notes, and snippets.

@hrsano645
Last active June 7, 2019 02:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hrsano645/8ae14698c4443824343c638145a80e6d to your computer and use it in GitHub Desktop.
Save hrsano645/8ae14698c4443824343c638145a80e6d to your computer and use it in GitHub Desktop.
import asyncio
from pyppeteer import launch
from pathlib import Path
import time
# ref:https://qiita.com/horikeso/items/69528c2b21ede15a56ee
download_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中の監視をさせる必要があるっぽい
# 終了処理がわからん
# await browser.close()
asyncio.get_event_loop().run_until_complete(main())
watch_dir = Path(download_path)
filename = ""
while not filename or filename.endswith(".crdownload"):
# ファイルを見て監視する
watch_dir_list = list(watch_dir.glob("*"))
if watch_dir_list:
filename = str(watch_dir_list[0])
print(filename)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment