SHARE
TWEET

Untitled

nks43 Jun 27th, 2019 128 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import csv
  4.  
  5. link="https://codeforces.com/blog/entry/55274"
  6. req=requests.get(link)
  7. soup=BeautifulSoup(req.content,'html5lib')
  8. required=soup.find('div',attrs={'class':'ttypography'})
  9. ultra_req=required.find_all('div',attrs={'class':'spoiler'})
  10.  
  11. filename = 'problemsOnVariousTypes.csv'
  12. problem_list=[]
  13. p=1
  14. with open(filename, 'w') as f:
  15.     w = csv.DictWriter(f,['Problem_number','Catogery','Problem_details'])
  16.     w.writeheader()
  17.     for row in ultra_req:
  18.         cat_type=row.find('b',attrs={'class':'spoiler-title'})
  19.         problems=row.find('div',attrs={'class':'spoiler-content'})
  20.         problems=row.find_all('p')
  21.         for problem in problems:
  22.             push={}
  23.             push['Problem_number']=p
  24.             push['Catogery']=cat_type.text
  25.             push['Problem_details']=problem.text
  26.             w.writerow(push)
  27.             p=p+1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top