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

如何使用Pandas提取指定网页内容中的邮箱地址?

从指定网页表格提取邮箱地址的实现方案

步骤说明

  1. 读取网页表格数据
  2. 定位包含邮箱的列(邮箱通常嵌套在地址类文本中,格式如E-mail: xxx@xxx.com)
  3. 用正则表达式精准提取邮箱内容
  4. 整理结果并保存

完整代码示例

import pandas as pd
import re

# 读取网页中的表格数据
df = pd.read_html('http://www.advpalata28.ru/reestr/reestr-advokatov/')[0]

# 查看表格列名,确认包含邮箱的列(示例中假设列名为'Адрес',需根据实际调整)
# print(df.columns)

# 从目标列提取邮箱地址,正则表达式匹配E-mail:后的邮箱内容
df['提取的邮箱'] = df['Адрес'].str.extract(r'E-mail:\s*([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})')

# 过滤空值,得到去重后的纯邮箱列表
clean_emails = df['提取的邮箱'].dropna().unique().tolist()

# 保存结果到Excel文件
pd.DataFrame({'邮箱地址': clean_emails}).to_excel('提取的邮箱列表.xlsx', index=False, encoding='utf-8')

# 打印提取结果
print("提取到的邮箱地址:")
for email in clean_emails:
    print(email)

单独处理示例文本的方法

如果需要单独处理类似示例的文本字符串,可直接用正则匹配:

import re

sample_text = "676740, Амурская обл, Архара пгт, Ленина ул, 76 E-mail: advokat527@mail.ru"
match_result = re.search(r'E-mail:\s*([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})', sample_text)
if match_result:
    extracted_email = match_result.group(1)
    print(f"提取到的邮箱:{extracted_email}")

注意事项

  • 若表格列名不是Адрес,需先通过print(df.columns)查看实际列名,替换代码中的列名参数
  • 正则表达式可根据实际邮箱格式微调,确保覆盖所有可能的邮箱样式

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.24 23:45:40