Program

Pythonでスクレイピング3(日付の変換)

今治市役所お知らせの取得(日付の変換) import datetime from bs4 import BeautifulSoup from urllib.request import urlopen from urllib.parse import urljoin def date_conv(hiduke): return str(datetime.date(hiduke.year, hiduke.month, hiduke.day)…

Pythonでスクレイピング2(相対アドレスの変換)

今治イベント情報を取得(相対アドレスの変換) import urllib.request from bs4 import BeautifulSoup from urllib.parse import urljoin url = "http://www.city.imabari.ehime.jp/event/" html = urllib.request.urlopen(url).read() soup = BeautifulSou…

Pythonでメール送信

Gmailで送信 import email.mime.text from smtplib import SMTP host, port = 'smtp.gmail.com', 587 fromaddr = '自分のメールアドレス' toaddr = '相手先のメールアドレス' gmail_passwd = 'パスワード' #タイトル subject = 'テスト' #本文 msg_body = '…

PythonでTwitter

https://pypi.python.org/pypi/twittertwitterインストール $ pip install twitter プログラム from twitter import * OAUTH_TOKEN = '' OAUTH_SECRET = '' CONSUMER_KEY = '' CONSUMER_SECRET = '' t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONS…

Pythonでメール受信

愛媛県警察 安全・安心メールマガジンの不審者情報のメール取得 import imaplib, re user = "" password = "" label = "" gmail = imaplib.IMAP4_SSL("imap.gmail.com") #ログイン gmail.login(user, password) #ラベル一覧 #gmail.list() #ラベル選択 gmail…

PythonでRSS取得

おいでや!NEWSのRSSを取得feedparserインストール $ pip install feedparser プログラム import feedparser url="http://oideya.exblog.jp/index.xml" fdp = feedparser.parse(url) for entry in fdp.entries: print("{} {}".format(entry.title, entry.lin…