24
24

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 3 years have passed since last update.

Selenium Pythonでタブを切り替えながら実行する

Posted at

概要

検索結果一覧を出しながら、違うタブで詳細ページを開きながらスクレイピングしたい場合があったので方法を備忘録的に記載しておきます。

方法


from selenium import webdriver

# ChoromeDriver
driver = webdriver.Chrome(executable_path='chromedriver.exe')

# URLアクセス
driver.get('https://qiita.com/')

# 新しいタブを作成する
driver.execute_script("window.open()")

# 新しいタブに切り替える
driver.switch_to.window(driver.window_handles[1])

# 新しいタブでURLアクセス
driver.get('https://www.google.com')

#前のタブに切り替え
driver.switch_to.window(driver.window_handles[0])
24
24
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
24
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?