Advertisement
borsha06

atcoder

Feb 23rd, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Feb 24 11:28:32 2017
  4.  
  5. @author: borsha
  6. """
  7.  
  8. import requests
  9.  
  10. from bs4 import BeautifulSoup
  11.  
  12. def get_code(url):
  13.     req=requests.get(url)
  14.     code=req.text
  15.     return code
  16. def check(text):
  17.     return type(text)!= type(None) and text.find("\n")==-1
  18. def bs4_get(content,func):
  19.     soup=BeautifulSoup(content,"html.parser")
  20.     get_all=soup.find_all(string=func)
  21.     return get_all
  22.    
  23. def atcoder():
  24.     url="https://atcoder.jp/"
  25.     texts=get_code(url)
  26.     all_text=bs4_get(texts,check)
  27.    
  28.     start=all_text.index("Upcoming Contests")+2
  29.     end=all_text.index("Recent Contests")  
  30.     all_text=all_text[start:end]
  31.    
  32.     file=open("upcoming contests.txt",'w')
  33.     for i in all_text:
  34.         file.write(i)
  35.         file.write("\n")
  36.     file.close()    
  37.        
  38.  
  39. atcoder()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement