You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python实现Robinhood网站‘show more’按钮点击并提取公司About段落?

解决Robinhood公司About板块"Show More"点击与内容提取问题

核心问题分析

静态爬虫(如requests)无法获取需要通过点击"Show More"动态加载的内容,必须使用浏览器自动化工具模拟用户交互。

解决方案(基于Selenium)

1. 安装依赖

首先安装所需包及对应浏览器驱动:

pip install selenium

同时下载对应浏览器的驱动(如ChromeDriver需与本地Chrome版本匹配)。

2. 完整代码示例

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 初始化Chrome浏览器
driver = webdriver.Chrome()

# 替换为目标公司的Robinhood页面URL
target_url = "https://robinhood.com/stocks/AAPL"
driver.get(target_url)

try:
    # 等待"Show More"按钮可点击(最长等待10秒)
    show_more_btn = WebDriverWait(driver, 10).until(
        EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Show More')]"))
    )
    
    # 若直接点击失败,用JS强制触发点击
    driver.execute_script("arguments[0].click();", show_more_btn)
    
    # 等待About板块完整内容加载
    about_container = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "div[data-testid='about-section']"))
    )
    
    # 提取完整文本
    full_about_content = about_container.text
    print(full_about_content)

finally:
    # 关闭浏览器
    driver.quit()

关键注意事项

  • 元素选择器更新:Robinhood的页面元素类名/属性可能变更,需通过浏览器F12开发者工具查看最新的"Show More"按钮和About板块选择器。
  • 反爬应对:若遇到反爬拦截,改用undetected-chromedriver绕过检测:
    pip install undetected-chromedriver
    
    初始化浏览器替换为:
    import undetected_chromedriver as uc
    driver = uc.Chrome()
    
  • 登录需求:部分页面可能需要登录才能访问,需添加登录逻辑(输入账号密码或使用Cookie登录)。

内容的提问来源于stack exchange,提问作者abdullah Hashim

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 02:30:17