声明:本文仅讨论商家主动公开数据的整理与导出,不涉及破解登录、验证码识别、风控对抗、非公开接口调用或隐私数据抓取。请遵守服务条款、robots.txt,请勿将数据用于骚扰、诈骗或非法营销。
在外贸业务、供应链对接、市场调研等场景中,有时需要整理阿里巴巴国际站商家的公开联系方式。很多商家会在商品详情页、店铺首页或公开资料中展示公司名、邮箱、电话等信息。人工复制效率低,容易遗漏,因此可以借助脚本或轻量工具做“公开数据整理”。
本文标题中的“实时导出”,指的是对当前已经公开、且允许访问的页面进行即时解析,而不是绕过平台登录、验证码或风控。工具获取的也只是商家主动公开的数据。如果页面没有展示联系方式,就不应尝试通过非正常手段获取。
一个合规的“阿里巴巴国际站商家实时导出工具”通常只做以下几件事:
需要 Python 3.8+,安装依赖:
pip install requests beautifulsoup4把你确认可以访问、无需登录、且页面中已经公开联系方式的阿里巴巴国际站页面 URL 放入代码中的 urls 列表。建议一次只处理少量页面,并在每次请求之间加入延时。
将下方代码保存为 export_alibaba_contacts.py,运行:
python export_alibaba_contacts.py脚本会生成 alibaba_public_contacts.csv,包含“来源URL”“公司/标题”“邮箱”“电话”等列。建议导出后人工核对,避免把平台客服电话、无关号码误当成商家电话。
以下代码演示了从公开页面中提取邮箱、电话并导出 CSV 的基本思路。国际站页面结构可能变化,且很多内容由 JavaScript 动态渲染,代码不保证对所有页面有效,请勿用于违规批量抓取。
import csv
import re
import time
from urllib.parse import urlparse
from urllib.robotparser import RobotFileParser
import requests
from bs4 import BeautifulSoup
HEADERS = {
"User-Agent": (
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/124.0.0.0 Safari/537.36"
),
"Accept-Language": "en-US,en;q=0.9,zh-CN;q=0.8",
}
EMAIL_RE = re.compile(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
PHONE_RE = re.compile(r"\+?\d[\d\s\-()]{7,}\d")
def can_fetch(url: str) -> bool:
"""检查 robots.txt 是否允许抓取"""
parsed = urlparse(url)
robots_url = f"{parsed.scheme}://{parsed.netloc}/robots.txt"
rp = RobotFileParser()
rp.set_url(robots_url)
try:
rp.read()
except Exception as e:
print(f"读取 robots.txt 失败:{e}")
return False
return rp.can_fetch(HEADERS["User-Agent"], url)
def fetch_html(url: str):
"""获取公开页面 HTML,单线程、限速、超时"""
if not can_fetch(url):
print(f"robots.txt 不允许抓取:{url}")
return None
try:
resp = requests.get(url, headers=HEADERS, timeout=15)
resp.raise_for_status()
return resp.text
except Exception as e:
print(f"请求异常:{e},URL:{url}")
return None
def clean_phone(phone: str) -> str:
"""简单清洗电话"""
phone = re.sub(r"[\s\-()]", "", phone)
if phone.startswith("00"):
phone = "+" + phone[2:]
return phone
def extract_contacts(html: str, url: str):
"""从公开 HTML 中提取公司名、邮箱、电话"""
soup = BeautifulSoup(html, "html.parser")
text = soup.get_text(separator=" ", strip=True)
# 公司名 / 页面标题
company = ""
if soup.title:
company = soup.title.get_text(strip=True)
h1 = soup.find("h1")
if h1:
company = h1.get_text(" ", strip=True)
emails = set(EMAIL_RE.findall(text))
phones = set(PHONE_RE.findall(text))
# 提取 mailto: 和 tel: 链接
for a in soup.find_all("a", href=True):
href = a["href"].strip()
if href.lower().startswith("mailto:"):
emails.add(href[7:].split("?")[0])
if href.lower().startswith("tel:"):
phones.add(href[4:])
emails = {e.strip().lower() for e in emails if e.strip()}
phones = {clean_phone(p) for p in phones if clean_phone(p)}
return company, sorted(emails), sorted(phones)
def export_csv(rows, output_path: str):
"""导出 CSV"""
with open(output_path, "w", newline="", encoding="utf-8-sig") as f:
writer = csv.writer(f)
writer.writerow(["来源URL", "公司/标题", "邮箱", "电话"])
writer.writerows(rows)
def main():
# 请替换为公开且允许访问的页面 URL
urls = [
# "https://www.alibaba.com/product-detail/xxxxxxxx.html",
]
interval = 8 # 每次请求间隔,避免对平台造成压力
rows = []
for url in urls:
print(f"正在处理:{url}")
html = fetch_html(url)
if not html:
continue
company, emails, phones = extract_contacts(html, url)
if not emails and not phones:
rows.append([url, company, "", ""])
else:
max_len = max(len(emails), len(phones), 1)
for i in range(max_len):
rows.append([
url,
company,
emails[i] if i < len(emails) else "",
phones[i] if i < len(phones) else "",
])
time.sleep(interval)
export_csv(rows, "alibaba_public_contacts.csv")
print(f"导出完成,共 {len(rows)} 条记录。")
if __name__ == "__main__":
main()如果你只是做本地整理,也可以把公开页面手动保存为 HTML,然后用 BeautifulSoup 读取本地文件。这种方式更安全,也更容易控制频率:
from bs4 import BeautifulSoup
import re
def extract_from_local(file_path):
with open(file_path, "r", encoding="utf-8", errors="ignore") as f:
html = f.read()
soup = BeautifulSoup(html, "html.parser")
text = soup.get_text(" ", strip=True)
emails = set(re.findall(r"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}", text))
phones = set(re.findall(r"\+?\d[\d\s\-()]{7,}\d", text))
return {
"emails": sorted(emails),
"phones": sorted({re.sub(r"[\s\-()]", "", p) for p in phones}),
}
print(extract_from_local("public_page.html"))本文分享的“阿里巴巴国际站商家实时导出软件”实现思路,核心是:读取公开页面 → 解析公开联系方式 → 去重 → 导出 CSV。它适合小规模、合规的数据整理场景,不能也不应被用于非法抓取或骚扰营销。
技术本身是中性的,关键在于使用方式。希望这篇教程能帮助你在合规前提下提升整理效率。平台页面结构会变化,代码也可能需要根据实际情况调整;若页面需要登录或出现验证码,请立即停止,不要尝试绕过。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。