論文のタイトル一覧が欲しかった
IEEEとかの学会にでると、論文集がもらえます。
その論文集のタイトル一覧とがあればいいなーと思ったのでスクレイピングしました。
実行環境
次に実行環境を示します。
Soft and Hard | バージョン |
---|---|
Windowds 10 Pro | 17763.316 build |
python | 2. 7 |
code
ライブラリは、beautifulSoupを使用しました
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup as bf
import csv
def getHtml(file_name):
file = open(str(file_name))
html = bf(file,'lxml')
file.close
return html
def getTitle(html, cvlist):
for t in html.find_all("", class_="pTtl"):
csvlist = []
text=t.get_text()
text = text.encode('utf-8')
csvlist.append(text)
writecsv.writerow(csvlist)
if __name__ == "__main__":
html = getHtml('index.html')
f = open("output.csv", "w")
writecsv = csv.writer(f)
f.close()
まとめ
今後も使うと思うので、もっと使いやすいように改良していきたいと思います。