New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
提出一覧ページを見るのにログインが必要になった #23
Comments
以下のようなログイン処理で提出ページの閲覧はできそうです。 【前提】環境変数に以下の値を設定しておく
# Python Version: 3.x
import os
import sys
import time
import bs4
import requests
sess = requests.Session()
def get_html(url: str) -> bs4.BeautifulSoup:
resp = sess.get(url)
resp.raise_for_status()
soup = bs4.BeautifulSoup(resp.content, 'lxml')
time.sleep(0.5)
return soup
# あらかじめ環境変数に設定したIDとパスワードを取得
atcoder_id = os.environ.get('ATCODER_ID')
atcoder_password = os.environ.get('ATCODER_PASSWORD')
# 一度ログインページを開き、csrf_tokenを取得しておく(ログイン時に必要)
csrf_token = get_html('https://atcoder.jp/login').find(name='input', attrs={'name': 'csrf_token'})['value']
# for debug
print("id:" + atcoder_id)
print("password:" + atcoder_password)
print("csrf_token:" + csrf_token)
# id, パスワード, csrf_token を使ってログイン
resp = sess.post('https://atcoder.jp/login', { 'username': atcoder_id, 'password': atcoder_password, 'csrf_token': csrf_token})
# for debug
print("login info:" + str(resp))
# 以降ログインしたアカウントで提出ページの取得ができる
print (get_html('https://atcoder.jp/contests/abc001/submissions')) |
ありがとうございます!実は問題点はもう二つほどあります:
後者は実際に Twitter が終焉してから考えればよいとして、前者が気になっています。AtCoderProblems がどうされているかとか、ご存じないでしょうか…… |
軽く聞いてみました。 自分の ID を使ってるみたいです。 AtCoder のアクセス制御は秒間1アクセスまで、みたいな感じのようで、 atgolfer においては、get_html のディレイを 1 秒とかに伸ばせば安全だと思います。 |
|
返信遅れてすいません。
情報助かります!ただやっぱり |
#24 書いてみました。今 Twitter API のほうでアレでアレですが…… |
投稿に成功したのでまあ多分大丈夫だと思います。マージしてデプロイします |
ありがとうございます! |
https://twitter.com/atcoder/status/1648939398241853440
The text was updated successfully, but these errors were encountered: