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

如何获取IRGlobal顾问页面需点击才显示的邮箱地址?

提取IRGlobal顾问页面邮箱的解决方案

核心思路

该网站的邮箱通过动态接口加载:点击邮件按钮时,前端会携带按钮的data-id参数请求后端接口,返回真实邮箱地址。无需模拟打开邮件客户端,直接抓取这个接口就能拿到目标邮箱。

实现步骤

  1. 从顾问页面提取邮件按钮的data-id值
  2. 调用网站的专属邮箱接口,传入data-id获取真实邮箱

代码示例(Python)

方法1:BeautifulSoup + Requests(无浏览器,速度快)

import requests
from bs4 import BeautifulSoup

def get_advisor_email(advisor_url):
    # 1. 抓取页面源码,提取按钮的data-id
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36"
    }
    page_res = requests.get(advisor_url, headers=headers)
    soup = BeautifulSoup(page_res.text, "html.parser")
    
    # 定位带data-id的邮件按钮
    email_btn = soup.find("a", attrs={"data-id": True, "class": lambda c: c and "email" in c.lower()})
    if not email_btn:
        return None
    data_id = email_btn["data-id"]
    
    # 2. 请求邮箱接口获取真实地址
    api_url = "https://irglobal.com/wp-admin/admin-ajax.php"
    params = {
        "action": "get_email",
        "id": data_id
    }
    api_res = requests.get(api_url, params=params, headers=headers)
    api_res.raise_for_status()
    
    # 解析接口返回的JSON数据
    try:
        email_data = api_res.json()
        return email_data.get("email")
    except ValueError:
        return None

# 测试示例
print(get_advisor_email("https://irglobal.com/advisor/angus-forsyth"))
print(get_advisor_email("https://irglobal.com/advisor/ns-shastri/"))

方法2:Selenium(适配动态渲染页面)

如果页面有反爬机制或按钮动态加载,用Selenium确保能稳定获取data-id:

from selenium import webdriver
from selenium.webdriver.common.by import By
import requests

def get_advisor_email_selenium(advisor_url):
    options = webdriver.ChromeOptions()
    options.add_argument("--headless=new")  # 无头模式运行浏览器
    driver = webdriver.Chrome(options=options)
    
    try:
        driver.get(advisor_url)
        # 定位邮件按钮并提取data-id
        email_btn = driver.find_element(By.CSS_SELECTOR, "a[data-id][class*='email']")
        data_id = email_btn.get_attribute("data-id")
        
        # 调用接口获取邮箱
        headers = {
            "User-Agent": driver.execute_script("return navigator.userAgent;")
        }
        api_url = "https://irglobal.com/wp-admin/admin-ajax.php"
        params = {"action": "get_email", "id": data_id}
        api_res = requests.get(api_url, params=params, headers=headers)
        return api_res.json().get("email")
    finally:
        driver.quit()

# 测试
print(get_advisor_email_selenium("https://irglobal.com/advisor/angus-forsyth"))

适配说明

  • 两种方案均适配所有顾问页面:只要页面的邮件按钮带有data-id属性,且接口规则不变,就能正常提取邮箱。
  • 务必添加User-Agent模拟浏览器请求,避免被网站拦截。
  • 若后续接口返回格式变化,仅需调整JSON解析部分即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.17 20:22:34