0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

uploader.jp(ux.getuploader.com)からファイルをコマンドラインで取得する

Last updated at Posted at 2023-08-02

はじめに

https://uploader.jp/(ux.getuploader.com)からファイルをコマンドラインで取得すべくファイルの直リンクをコピーしても、時間が経ってからこのリンクを開いたら機能しません。しかしながら、このためだけにSeleniumを使うのも面倒です。
そこで、URLを指定したらダウンロードするスクリプトを組みました(というか組んでもらった)。

スクリプト

Python

import sys
import requests
from bs4 import BeautifulSoup

url = sys.argv[1]
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')

token = soup.find('input', attrs={'name': 'token', 'type': 'hidden'})['value']
fileName = soup.find('meta', attrs={'name': 'keywords'})['content'].split(',')[0]
userName = soup.find('a', attrs={'class': 'navbar-brand'})['href'].split('/')[-2]
index = url.split('/')[-1]

downloadUrl = f'https://downloadx.getuploader.com/g/{token}/{userName}/{index}/{fileName}'
r_zip = requests.get(downloadUrl)
with open( './' + fileName , 'wb') as file:
    file.write(r_zip.content)

使用法

オプションにダウンロードリンクを付けるのみ。

謝辞

原型を書いてくださった部活の先輩に感謝します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?