Guest User

Wikipedia Code

a guest
Jun 4th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import wikipedia as wp
  4.  
  5.  
  6. def add_section_info(search):
  7.  
  8.     table_of_contents = []
  9.     dict_of_section_info = {}
  10.  
  11.     toc = wp.page(search).sections
  12.     for item in toc:
  13.         section = wp.page(search).section(item)
  14.         if section == "":
  15.             continue
  16.         else:
  17.             dict_of_section_info[item] = section
  18.  
  19.     with open("Section_Info.txt",'a') as sect:
  20.         sect.write(search)
  21.         sect.write("\n---------------------------------------------------------------------------\n")
  22.         for item in dict_of_section_info:
  23.             print item.encode("UTF-8")
  24.             print dict_of_section_info[item].encode("UTF-8")
  25.             sect.write(item.encode("UTF-8"))
  26.             sect.write("\n\n")
  27.             sect.write(dict_of_section_info[item].encode("UTF-8"))
  28.             sect.write("\n")
  29.         sect.write("##############################################################\n\n")
  30.  
  31.  
  32. with open("exactMatches.txt",'r') as f:
  33.     for line in f:
  34.         add_section_info(line)
Advertisement
Add Comment
Please, Sign In to add comment