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

如何用Beautiful Soup提取奥地利创业公司的所在地、标签及成立日期?

提取奥地利创业公司信息的解决方案

根据你提供的HTML结构和现有代码,你可以通过以下方式定位并提取所需的“所在地”“标签”和“成立日期”信息:

核心思路

每个目标字段都被包裹在带有特定类名的div容器中(比如所在地对应wpbdp-field-based_in类,标签对应wpbdp-field-tags类,成立日期对应wpbdp-field-founded类),我们可以直接通过这些类名定位到字段容器,再提取其中.value节点的文本内容。

完整代码示例

import bs4
import requests

# 请求页面
result = requests.get('https://www.eu-startups.com/directory/wpbdp_category/austrian-startups')
content = bs4.BeautifulSoup(result.text, 'lxml')

# 获取所有公司的详情容器
all_listings = content.select('.listing-details')

# 遍历每个公司详情,提取信息
for listing in all_listings:
    # 提取公司名称(可从详情内或你原有的.listing-title类提取)
    company_name = listing.select_one('.wpbdp-field-business_name .value').get_text(strip=True)
    
    # 提取所在地
    location = listing.select_one('.wpbdp-field-based_in .value').get_text(strip=True)
    
    # 提取标签
    tags = listing.select_one('.wpbdp-field-tags .value').get_text(strip=True)
    
    # 提取成立日期
    founded_year = listing.select_one('.wpbdp-field-founded .value').get_text(strip=True)
    
    # 打印或存储信息
    print(f"公司名称: {company_name}")
    print(f"所在地: {location}")
    print(f"标签: {tags}")
    print(f"成立日期: {founded_year}")
    print("-" * 50)

补充定位方式

如果你更习惯通过字段标签文本(比如“Based in”)来定位,也可以用以下逻辑替代类名定位:

# 通过标签文本找所在地
location = listing.find('span', text='Based in').find_next_sibling('div', class_='value').get_text(strip=True)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 23:20:18