LoginSignup
0
3

More than 3 years have passed since last update.

PythonのSeleniumで秒速でスクレイピングする方法

Posted at

セレクタをXPATHで取得

Chromeの拡張機能のxPath Finderを使用し素早くページ上のXPATHを指定する。

image.png

そしてそこにsend_keysなどで入力項目を送る。

以下はSBI証券のログインのスクリプトの抜粋です。

try:
    browser.get('https://www.sbisec.co.jp/ETGate')
    username_field = browser.find_element_by_xpath('/html/body/table/tbody/tr[1]/td[2]/form/div/div/div/dl/dd[1]/div/input')
    username_field.clear()
    username_field.send_keys(username)
    password_field = browser.find_element_by_xpath("/html/body/table/tbody/tr[1]/td[2]/form/div/div/div/dl/dd[2]/div/input")
    password_field.send_keys(password)
    login_button = browser.find_element_by_xpath("/html/body/table/tbody/tr[1]/td[2]/form/div/div/div/p[2]/a/input")
    login_button.click()#click login
    time.sleep(5)

このパターンを使えばSeleniumを使ったプロジェクトが一気に捗ります。

更新履歴

  • 2020/06/06 新規作成
0
3
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
0
3