LoginSignup
12

More than 5 years have passed since last update.

ヤフーリアルタイム検索 selenium + python

Last updated at Posted at 2015-01-22

ヤフーのリアルタイム検索を自動で検索して、Firefox のタブに展開するselenium + python の script つくりました。

環境は、Mac に anaconda で python3 をいれて、selenium を install すると使えます。selenium は、anaconda をいれたあとで、pip install selenium するとインストールできます。windows ではまだ、検証していないです。。。すみません。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import sys,os,platform

# 新規タブをあけるキー操作を設定
newtab=Keys.CONTROL + 't'
# Mac かどうかの判定、キーがMac だと違う
if platform.system() == 'Darwin':
 newtab=Keys.COMMAND + 't'


# チェックする項目、気になっている事務次官、審議官クラスの官僚の名前を書きました。python2 用に、UTF8の指定をいれています。

slist=[u"西正典",u"板東久美子",u"前川喜平"]

driver = webdriver.Firefox()


for xkey in slist:
 # リアルタイム検索
 driver.get("http://realtime.search.yahoo.co.jp/realtime")
 driver.find_element_by_name("p").clear()
 driver.find_element_by_name("p").send_keys(xkey)
 driver.find_element_by_css_selector("input.b").click()
 # 最後になったら新規タブをつくらず抜ける
 if xkey == slist[-1]:
  break
 body = driver.find_element_by_tag_name("body")
 body.send_keys(newtab)

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
12