Created
March 22, 2023 06:13
-
-
Save theSoberSobber/1828693fe9e6e02b9785933b5e943b01 to your computer and use it in GitHub Desktop.
python scrape.py > out
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 sys, json; | |
import urllib.request | |
import bs4 as bs; | |
ap=json.load(urllib.request.urlopen("https://codeforces.com/api/user.status?handle=18o3"))["result"]; | |
for i in ap: | |
phtml = bs.BeautifulSoup(urllib.request.urlopen( f'https://codeforces.com/contest/{i["contestId"]}/submission/{i["id"]}'), "html.parser"); | |
try: | |
out=""; | |
code = phtml.body.find('pre', attrs={'id':'program-source-text'}).text; | |
for lno in range(len(code.splitlines())-7, len(code.splitlines())): | |
out+=code.splitlines()[lno]+"\n"; | |
print(out); | |
except: | |
with open('fail', 'w') as f: | |
with redirect_stdout(f): | |
print(i); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
scrapes rr sir ke submission ke last 6 lines