Python スクレイピング seleniumでマウスオーバーする

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By

# SeleniumでChromeブラウザを開く
driver = webdriver.Chrome()

# ページにアクセスする
driver.get("https://minkabu.jp/pick/balance/buy")

#マウスオーバーする
actions = ActionChains(driver)
actions.move_to_element(driver.find_element(By.XPATH,'//*[@id="dayLabel_20230101"]')).perform()

# ブラウザを終了する
driver.quit()


※Selenium 4.3.0 以降では find_element_by_* メソッドは廃止されました

ネタ元

teratail.com

Python スクレイピング BeautifulSoupを使って idがdayLabel_で始まるものだけ取得する方法

seleniumとBeautifulSoupを使う

インストール

pip install beautifulsoup4
pip install selenium


コード

# SeleniumでChromeブラウザを開く
driver = webdriver.Chrome()

# ページにアクセスする
driver.get("https://minkabu.jp/pick/balance/buy")

# ページのHTMLを取得し、Beautiful Soupで解析する
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')

ret = soup.find_all(id=lambda x: x and x.startswith('dayLabel_'))

python exe化はpyinstallerよりNuitkaがいいらしい

オープンソースのApache 2.0ライセンスで公開されている(商用利用可能)
とのこと

インストール

pip install nuitka
pip install ordered-set
pip install zstandard


1ファイルにまとめてアイコンまでつける例

nuitka hogehoge.py --onefile --windows-icon-from-ico=hoge.ico


www.idnet.co.jp