6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonでニュース速報(嫌儲)のスレッド一覧を取得してみる。

Posted at

Pythonの勉強がてらニュース速報(嫌儲)のスレッド一覧を取得してみた。
####環境

  • Python 2.7.5
  • Mac OSX 10.9
get_kenmo.py
# -*- coding: utf-8 -*-
import urllib

def get_kenmo():
    response = urllib.urlopen('http://engawa.2ch.net/poverty/subject.txt')
    html = unicode(response.read(), "cp932", 'ignore').encode("utf-8")
    for line in html.split("\n"):
        if line != "":
            print(line.split("<>", 2)[1])

if __name__ == "__main__":
    get_kenmo()

####躓いたところ

  • urllib.requestがない?→urllib.requestは3系のライブラリで、2.7系はurllibだった。
  • 文字化ける!→cp932(shift_jis)に変換しないとだめだった。
  • 改行コードで分割できない!→¥nじゃなくて\nで分割しないとだめだった(\はalt+¥で入力。よく忘れる)。
6
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?