pythonで決算プロの『 全上場企業・短信XBRLデータ』のxlsをcsvで保存

ありがとうchatGPT!

import re
import requests
import pandas as pd

url = "http://ke.kabupro.jp/doc/down40.htm"
res = requests.get(url)

# XLSファイルのリンクを取得
match = re.search(r'<a.*href="(.*\.xls)".*>', res.text)
if match:
    xls_link = match.group(1)
    xls_link = "http://ke.kabupro.jp/doc/" + xls_link
    xls_file = requests.get(xls_link)

    with open("down40.xls", "wb") as f:
        f.write(xls_file.content)

    df = pd.read_excel("down40.xls")
    df.to_csv("down40.csv", index=False, encoding='shift_jis', errors='ignore')
else:
    print("XLSファイルのリンクが見つかりません")

Google Analytics カスタム URL の使い方

Webページ:Google アナリティクスのデモとツール用サイトのキャンペーン URL 生成ツール

https://ga-dev-tools.web.app/campaign-url-builder/

カスタム キャンペーンのデータを確認する方法(旧)

キャンペーン レポートを確認する手順は次のとおりです。
Google アナリティクスにログインします。
目的のビューに移動します。
[レポート] を開きます。
[集客]、[キャンペーン] の順に選択します。

GA4(Googleアナリティクス4)の場合

■流入数の調べ方
「集客」⇒「ユーザー獲得」から設定したキャンペーンの流入数がわかります。

ネタ元

junichi-manga.com

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_'))