那个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

请您先登陆,再发跟帖!