2014年12月31日水曜日

【MIYADAI.com】からテクストをパクる

さてさて、準備は整った訳ですので、そろそろ解析ネタを集めねばならん。
とのことで、ここからネタを集めることにします。


早速ですが、python+BeautifulSoupからいってみます。
話は横にそれますが、BeautifulSoupって風俗があっても、おかしくはないと思います。
誰かが、すでに商標登録してたら、笑えます。


# -*- coding: utf-8 -*-
from urllib import urlopen
from bs4 import BeautifulSoup

soup = BeautifulSoup(urlopen('http://www.miyadai.com/index.php?itemid=1061'))
print soup.title.string

file = open(soup.title.string+".txt", "w")
file.write(soup.title.string)

for h in soup.findAll(**{"class":"itembody"}):
 l = len(h.contents)
 for n in range(0, l):
  t   = str(h.contents[n])
  t1 = t.replace("<br/>","")
  t2 = t1.replace("<b>","")
  t3 = t2.replace("<b","")
  print(t3)
  file.write(t3)

file.close()
# EOF #

お恥ずかしい話ですが<br/>がど〜しても取れないんで、ズルしました(ついでに、<b>、”<b/>もね)。
まあ、あんまし細かいこと言ってると老けるので、不本意ながら我慢しておきます。

0 件のコメント:

コメントを投稿