来源:互联网 更新时间:2026-06-09 14:41
你可能会遇到这样一个场景:盯着网页上一大堆结构化表格数据,心想——“这些要是能一键导入Excel,该有多好?” 别急,这事儿靠AI就能搞定。这里就以一个真实案例来演示:从 Amplify Partners 的投资组合页面,把每一个被投公司的名称、所在地、状态、链接、团队成员、里程碑和文章等信息,统统爬下来存进一个Excel文件。

开始之前,需要给AI写一段提示词。目标非常清晰:用Python写一个爬虫脚本,完成以下任务——
Amplifypartnersportfolio.xlsx;role="listitem" 的 div 元素,逐个提取其中包含的以下信息:mob-name 的 div 文本 → 写入 Excel 第1列(Name);copy-wr 的 div 下 p 标签文本 → 写入第2列(Location);fs-cmsfilter-field="status" 的 div 文本 → 写入第3列(Status);mob-link 的 div 文本 → 写入第4列(Link);class="flex-vertical gap-4" 的 div 中所有 p 标签文本,过滤掉“TEAM”和空字符串 → 写入第5列(Team);div 中所有 p 文本,过滤掉“Milestones”和空字符串 → 写入第6列(Milestones);div 中所有 p 文本,过滤掉“Articles”和空字符串 → 写入第7列(Articles);下面是 Deepseek 据此生成的 Python 代码,核心逻辑清晰,直接可用:
import requests
from bs4 import BeautifulSoup
import openpyxl
workbook = openpyxl.Workbook()
sheet = workbook.active
sheet.title = "Amplify Partners Portfolio"
sheet['A1'] = 'Name'
sheet['B1'] = 'Location'
sheet['C1'] = 'Status'
sheet['D1'] = 'Link'
sheet['E1'] = 'Team'
sheet['F1'] = 'Milestones'
sheet['G1'] = 'Articles'
url = 'https://www.amplifypartners.com/portfolio'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
list_items = soup.find_all('div', role='listitem')
row = 2
for item in list_items:
try:
name_div = item.find('div', class_='mob-name')
name = name_div.text.strip() if name_div else ''
print(f"Extracted Name: {name}")
sheet[f'A{row}'] = name
location_div = item.find('div', class_='copy-wr')
location = location_div.find('p').text.strip() if location_div and location_div.find('p') else ''
print(f"Extracted Location: {location}")
sheet[f'B{row}'] = location
status_div = item.find('div', {'fs-cmsfilter-field': 'status'})
status = status_div.text.strip() if status_div else ''
print(f"Extracted Status: {status}")
sheet[f'C{row}'] = status
link_div = item.find('div', class_='mob-link')
link = link_div.text.strip() if link_div else ''
print(f"Extracted Link: {link}")
sheet[f'D{row}'] = link
team_div = item.find('div', class_='flex-vertical gap-4')
if team_div:
team_members = [p.text.strip() for p in team_div.find_all('p') if p.text.strip() not in ['TEAM', '']]
team_str = ', '.join(team_members)
print(f"Extracted Team: {team_str}")
sheet[f'E{row}'] = team_str
milestones_div = item.find_all('div', class_='flex-vertical gap-4')[1] if len(item.find_all('div', class_='flex-vertical gap-4')) > 1 else None
if milestones_div:
milestones = [p.text.strip() for p in milestones_div.find_all('p') if p.text.strip() not in ['Milestones', '']]
milestones_str = ', '.join(milestones)
print(f"Extracted Milestones: {milestones_str}")
sheet[f'F{row}'] = milestones_str
articles_div = item.find_all('div', class_='flex-vertical gap-4')[2] if len(item.find_all('div', class_='flex-vertical gap-4')) > 2 else None
if articles_div:
articles = [p.text.strip() for p in articles_div.find_all('p') if p.text.strip() not in ['Articles', '']]
articles_str = ', '.join(articles)
print(f"Extracted Articles: {articles_str}")
sheet[f'G{row}'] = articles_str
row += 1
except Exception as e:
print(f"Error processing item: {e}")
workbook.sa ve('F:/Amplifypartnersportfolio.xlsx')
print("Data sa ved to Amplifypartnersportfolio.xlsx")这个脚本的逻辑并不复杂,但覆盖了从网页抓取到Excel输出的完整链路:
openpyxl 创建Excel工作簿并设置表头;requests 拿下页面内容,BeautifulSoup 解析HTML;find 和 find_all 精准定位每一个数据槽;运行脚本后,控制台会逐条打印提取结果,方便你实时确认每一步都走对了。几分钟后,你就会在F盘根目录下看到 Amplifypartnersportfolio.xlsx,点开之后——所有数据整整齐齐地躺在表格里,分毫不差。
下饭影视APP下载安装指南
灵宝派对手游下载安装地址推荐
和平精英如何做到压枪稳-和平精英怎样才能压枪稳
下载浏览器app下载安装选择推荐
《Off Campus》第二季官宣:这对CP还在,但不再是主角
4D采矿者官网在哪下载 最新官方下载安装地址
免费影视剧APP推荐
儿子穿新中式现身大会堂 马斯克罕见用中文回应:他正在学习普通话
Elysium Above 履云录官网在哪下载 最新官方下载安装地址
抖音最火沙雕男生网名(精选100个)
名单曝光!库克、马斯克等将随团到访中国 黄仁勋不在其中
短剧《情绪超市》剧情介绍
短视频软件推荐
免费看电影的软件推荐
KuCoin基本面分析
苹果macOS 27将优化界面设计并测试AI驱动的Safari标签页自动分组功能
网络热词聊污是什么意思
网石18禁MMO《RAVEN2:渡鸦》大型更新推出全新职业“军阀”
洛克王国世界S2赛季狂欢怪谈介绍
SpaceX狂揽AI人才,马斯克亲自面试且不看简历背景
手机号码测吉凶
本站所有软件,都由网友上传,如有侵犯你的版权,请发邮件haolingcc@hotmail.com 联系删除。 版权所有 Copyright@2012-2013 haoling.cc