Advertisement
overloop

jisho.py

Nov 23rd, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Nov 23 23:36:47 2015
  4.  
  5. @author: User
  6. """
  7.  
  8. import urllib2
  9. from bs4 import BeautifulSoup
  10. from time import sleep
  11.  
  12. def words(needle):
  13.     url = 'http://classic.jisho.org/words?jap=*' + needle + '*&eng=&dict=edict&common=on'
  14.     f = urllib2.urlopen(url)
  15.     data = f.read()
  16.     #print data
  17.     soup = BeautifulSoup(data,'html.parser')
  18.     table = soup.find(id='word_result')
  19.     words = []
  20.     if table == None:
  21.         print needle + " yield 0 results"
  22.         return []
  23.     for tr in table.find_all('tr'):
  24.         c1 = tr.find(class_='kanji_column')
  25.         c2 = tr.find(class_='kana_column')
  26.         c3 = tr.find(class_='meanings_column')
  27.         if c1 != None and c2 != None and c3 != None:
  28.             words.append(c1.getText().strip() + "\t" + c2.getText().strip() + "\t" + c3.getText().strip())
  29.     return words
  30.  
  31. f = open('D:/w/jisho/sixth_grade.txt','w')
  32. for k in ['並','乱','乳','亡','仁','供','俳','値','傷','優','党','冊','処','刻','割','創','劇','勤','危','卵','厳','収','后','否','吸','呼','善','困','垂','城','域','奏','奮','姿','存','孝','宅','宇','宗','宙','宝','宣','密','寸','専','射','将','尊','就','尺','届','展','層','己','巻','幕','干','幼','庁','座','延','律','従','忘','忠','憲','我','批','担','拝','拡','捨','探','推','揮','操','敬','映','晩','暖','暮','朗','机','枚','染','株','棒','模','権','樹','欲','段','沿','泉','洗','派','済','源','潮','激','灰','熟','片','班','異','疑','痛','皇','盛','盟','看','砂','磁','私','秘','穀','穴','窓','筋','策','簡','糖','系','紅','納','純','絹','縦','縮','署','翌','聖','肺','背','胸','脳','腹','臓','臨','至','若','著','蒸','蔵','蚕','衆','裁','装','裏','補','視','覧','討','訪','訳','詞','誌','認','誕','誠','誤','論','諸','警','貴','賃','遺','郵','郷','針','鋼','閉','閣','降','陛','除','障','難','革','頂','骨']:
  33.     w = words(k)
  34.     f.write(k + "\n" + "\n".join(w).encode('utf8') + "\n\n")
  35.     sleep(5)
  36. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement