利用者:素手/Bot/ボクサー一覧.py
表示
< 利用者:素手
#coding:utf-8 #!/usr/bin/python -S import sys from urllib import urlopen import linecache import wikipedia import sys import codecs import re import linecache import MySQLdb yahoo = open("yahoo.txt","w") #yahoo = codecs.lookup('utf_8')[-1](yahoo) site = wikipedia.getSite("ja") pagename = u"男子ボクサー一覧" page = wikipedia.Page(site,pagename) wikipedia.output(u"Loading %s..." % pagename) for i in page.linkedPages(): try: print i yahoo.write(i.title()) if i.isRedirectPage() == True: text = i.getRedirectTarget().get() else: text = i.get(force = False, get_redirect=False, throttle = True, sysop = False, change_edit_time = True) for t in text.split("\n"): if t.find("{{DEFAULTSORT:") != -1: print t yahoo.write("\t"+t.replace("{{DEFAULTSORT:","").replace("}}","")+"\n") break else: print u"defaultなし" yahoo.write(u"defaultがありません\n") except wikipedia.IsRedirectPage(): print "\a" yahoo.write("redirect") print "\a"