Skip to content

Instantly share code, notes, and snippets.

@theSoberSobber
Created March 22, 2023 06:13
Show Gist options
  • Save theSoberSobber/1828693fe9e6e02b9785933b5e943b01 to your computer and use it in GitHub Desktop.
Save theSoberSobber/1828693fe9e6e02b9785933b5e943b01 to your computer and use it in GitHub Desktop.
python scrape.py > out
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);
@theSoberSobber
Copy link
Author

scrapes rr sir ke submission ke last 6 lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment