那個SSA上的AWI數據下載搞定了,用selsium browser driver

大概這樣:

#########################################################
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium_stealth import stealth
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
import pandas as pd
from io import StringIO

# 1. Set up Chrome options to avoid detection
options = Options()
options.add_argument("start-maximized") # Maximize window to mimic typical user behavior
options.add_experimental_option("excludeSwitches", ["enable-automation"]) # Exclude the automation switch
options.add_experimental_option('useAutomationExtension', False)
# You may also want to add a custom, realistic user agent string for an extra layer of customization
# options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36')

# 2. Initialize the WebDriver
driver = webdriver.Chrome(options=options)

# 3. Apply selenium_stealth
stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )

# 4. Navigate to the SSA website
driver.get("https://www.ssa.gov/oact/cola/awiseries.html")

html_string = driver.page_source

soup = BeautifulSoup(html_string, 'html.parser')

tbl = soup.find('table', attrs={'summary': "AWI series and annual changes"})

pd.read_html(StringIO(str(tbl)))[0].set_index('Year')

#########################################################

所有跟帖: 

我接下來要做 ssa retirement benefit calculator... -slow_quick- 給 slow_quick 發送悄悄話 slow_quick 的博客首頁 (576 bytes) () 01/03/2026 postreply 22:36:21

你會不會又收到SSA工作offer? -螺絲螺帽- 給 螺絲螺帽 發送悄悄話 螺絲螺帽 的博客首頁 (0 bytes) () 01/04/2026 postreply 08:03:18

若是能自己在本地計算機上算出能領到多少退休SS的退休金,非常感謝 -千萬裏- 給 千萬裏 發送悄悄話 (263 bytes) () 01/04/2026 postreply 01:44:00

可以在自己電腦上計算 -slow_quick- 給 slow_quick 發送悄悄話 slow_quick 的博客首頁 (309 bytes) () 01/04/2026 postreply 09:28:21

“這個PIA經過了Cost of Living Adjustment,變成了New PIA。”, 所以, 這個參數由政府 -螺絲螺帽- 給 螺絲螺帽 發送悄悄話 螺絲螺帽 的博客首頁 (242 bytes) () 01/04/2026 postreply 08:14:10

請您先登陸,再發跟帖!