-
백준 문제집 만들기 부분-자동화아무거나적어~ 2022. 8. 22. 18:12
문제 번호 불러오기
알고리즘 기초 1/2
알고리즘 기초
code.plus
요기 있는 문제들을 풀고 있는데 어떤 문제를 풀었는지 표시가 안돼서 불편해요
그래서 요기있는 문제들을 백준의 문제집 만들기 기능을 이용해서 문제집으로 만들어볼까 합니다
그러려면 요기 있는 문제들의 번호를 알아야 합니다.
일일이 들어가서 체크하기 귀찮으니 이를 자동화해 봅시다What is my user agent?
Every request your web browser makes includes your User Agent; find out what your browser is sending and what this identifies your system as.
www.whatismybrowser.com
아래 코드의 8번째 줄 INFO["User-Agent"] 를 위 윕사이트에서 얻은
user-agent 정보로 바꿔줍시다. 예를들어
headers = {"User-Agent": "나는 너무 모질라. 더 공부해야해"}12345678910111213141516171819202122import osimport requestsfrom bs4 import BeautifulSoupfrom pathlib import Pathfrom info import INFOdef parse_problem_number(url: str) -> list:headers = {"User-Agent": INFO["User-Agent"]}response = requests.get(url, headers=headers)soup = BeautifulSoup(response.text, "lxml")ret = []for anchor in soup.findAll('a', href=True):tmp = anchor['href']if "problem" in tmp:path = Path(tmp)ret.append(path.parts[-1])return retURL = "https://code.plus/course/41"print(parse_problem_number(URL))cs['10828', '9093', ... , '2225']
문제번호 입력
환경 : 크롬 브라우저
parsing 한 문제번호를 백준에 입력해봅시다
수동으로 하려면 아래 그림의 문제 번호 칸을 클릭 후 숫자를 입력한 다음 'enter' 키를 누르시면 됩니다!
이를 자동화해봅시다F12
복사한 selector 를 아래 코드의 3, 7 줄의 selector 복사해서 넣기 부분에 붙여넣기 합니다
"" 로 감싸서 넣으세요12345678const array = ['1', '2']array.forEach(function (item, index) {document.querySelector(selector 복사해서 넣기).value = itemvar e = jQuery.Event("keypress");e.which = 13; //choose the one you wante.keyCode = 13;$(selector 복사해서 넣기).trigger(e);});cs예시
12345678const array = ['1', '2']array.forEach(function (item, index) {document.querySelector("body > div.wrapper > div.container.content > div.row > form > div.col-md-8 > div.form-group > div > input").value = itemvar e = jQuery.Event("keypress");e.which = 13; //choose the one you wante.keyCode = 13;$("body > div.wrapper > div.container.content > div.row > form > div.col-md-8 > div.form-group > div > input").trigger(e);});cs콘솔창을 누르신 후 코드를 실행하시면 왼쪽과 같이 배열의 문제번호가 입력됩니다
우와 신기하다~! >~<
'아무거나적어~' 카테고리의 다른 글
python3 customized compare function (0) 2022.09.24 동아리 등록하신 분 백준 그룹에 등록하기 (0) 2022.09.03 Markdown with LaTex (0) 2022.07.15 cmp 함수 결과 (0) 2022.07.07 Colab 단축키 (0) 2022.07.06