声明:本文仅讨论商家主动公开数据的整理与导出,不涉及破解、绕过登录、验证码识别、风控对抗或非公开数据抓取。请遵守抖音平台规则,切勿将数据用于骚扰、诈骗或非法营销。
在电商运营、商务合作或市场调研中,有时需要整理抖音精选联盟商家的公开联系方式。很多商家会在店铺首页、商品详情页或公开资料中展示客服电话、联系电话。人工复制效率低,容易出错,因此可以借助轻量工具或脚本进行批量整理。
本文分享一款“抖音精选联盟商家电话自动导出软件”的使用思路,并附上一段可运行的 Python 代码。该软件/脚本只处理商家主动公开的数据,不涉及任何隐私数据或平台非公开接口。
以常见的导出工具为例,一般具备以下功能:
需要强调:如果商家没有公开电话,工具无法获取,也不应尝试通过非正常手段获取。
在浏览器中打开抖音精选联盟商家的公开页面,确认页面中展示了联系电话。然后右键“另存为”或按 Ctrl + S,将页面保存为 .html 文件,放入 input 文件夹。
不建议直接高频请求平台页面。手动保存公开页面既能降低平台压力,也能确保数据来源是公开可见的。
脚本依赖 beautifulsoup4,安装命令:
pip install beautifulsoup4将下方代码保存为 export_phones.py,然后运行:
python export_phones.py脚本会在 output 文件夹生成 phones.csv,包含“电话”和“来源文件”两列。
以下代码用于从本地保存的公开 HTML 文件中提取电话并导出 CSV。代码仅作技术学习,请勿用于违规抓取。
import os
import re
import csv
from bs4 import BeautifulSoup
# 匹配手机号和常见座机号
PHONE_PATTERN = re.compile(
r'(?:(?:\+?86)?1[3-9]\d{9}|0\d{2,3}[- ]?\d{7,8})'
)
def extract_phones_from_html(html: str):
"""从 HTML 文本中提取公开电话"""
soup = BeautifulSoup(html, "html.parser")
text = soup.get_text(separator=" ", strip=True)
phones = PHONE_PATTERN.findall(text)
# 提取 tel: 链接中的电话
for a in soup.find_all("a", href=True):
href = a["href"].strip()
if href.lower().startswith("tel:"):
phones.append(href[4:].strip())
cleaned = []
for phone in phones:
phone = re.sub(r"[\s-]", "", phone)
if phone.startswith("+86"):
phone = phone[3:]
if phone:
cleaned.append(phone)
return cleaned
def process_folder(input_dir: str, output_csv: str):
"""批量处理本地公开页面,导出电话 CSV"""
if not os.path.exists(input_dir):
print(f"输入目录不存在:{input_dir}")
return
out_dir = os.path.dirname(output_csv)
if out_dir:
os.makedirs(out_dir, exist_ok=True)
all_phones = {}
for root, _, files in os.walk(input_dir):
for file in files:
if not file.lower().endswith((".html", ".htm", ".txt")):
continue
path = os.path.join(root, file)
try:
with open(path, "r", encoding="utf-8", errors="ignore") as f:
html = f.read()
except Exception as e:
print(f"读取失败:{path},原因:{e}")
continue
phones = extract_phones_from_html(html)
for phone in phones:
all_phones.setdefault(phone, set()).add(file)
with open(output_csv, "w", newline="", encoding="utf-8-sig") as f:
writer = csv.writer(f)
writer.writerow(["电话", "来源文件"])
for phone, sources in sorted(all_phones.items()):
writer.writerow([phone, ";".join(sorted(sources))])
print(f"共提取 {len(all_phones)} 个去重电话,已导出到 {output_csv}")
if __name__ == "__main__":
process_folder("input", "output/phones.csv")如果你需要从公开链接获取页面,请务必确认目标页面允许访问,并遵守 robots.txt、平台协议和频率限制。示例中不提供绕过登录、验证码或风控的代码。
本文分享的“抖音精选联盟商家电话自动导出软件”使用思路,核心是:手动保存公开页面 → 脚本识别电话 → 去重导出 CSV。它适合小规模、合规的数据整理场景,不能也不应被用于非法抓取或骚扰营销。
技术本身是中性的,关键在于使用方式。希望这篇教程能帮助你在合规前提下提升整理效率。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。