搜索
首页web前端js教程如何使用代码演示构建 Crunchbase Scraper

在数据如金子般重要的时代,Crunchbase 就是一座金矿。它包含数千家公司简介、投资数据、领导地位、融资信息、新闻等等。 Crunchbase 抓取将使您能够获得黄金块(您需要的见解)并过滤掉所有碎片(与您无关的所有其他信息)。

在本文中,我们将引导您完成从头开始构建 Crunchbase scraper 的过程,包括所有技术细节和使用 Python 的代码,并提供一个工作演示供您遵循。话虽如此,您还应该了解构建 Crunchbase 刮刀是一项耗时的任务,并且一路上面临许多挑战。这就是为什么我们还将使用 Proxycurl 进行替代方法的演示,Proxycurl 是一种基于 API 的付费工具,可以为您完成工作。有了这两种选择,您可以权衡它们的优点并选择最适合您需求的一种。

以下是使用 Python 从网站中提取公司名称和总部城市的基本 Crunchbase 抓取工具的预览。

import requests
from bs4 import BeautifulSoup

url = 'https://www.crunchbase.com/organization/apple'
headers = {'User-Agent': 'Mozilla/5.0'}

response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')

name_section = soup.find('h1', class_='profile-name')
company_name = name_section.get_text(strip=True) if name_section else 'N/A'

headquarters_section = soup.find('span', class_='component--field-formatter field_type_text')
headquarters_city = headquarters_section.get_text(strip=True) if headquarters_section else 'N/A'

print(f"Company Name: {company_name}")
print(f"Headquarters City: {headquarters_city}")

现在,我们的替代方法 Proxycurl。它是一个相对高效的 Crunchbase 抓取工具,您只需使用几行代码即可提取相同的公司信息。这里的额外好处是您不必担心 HTML 解析或 Proxycurl 的任何抓取障碍。

import requests

api_key = 'YOUR_API_KEY'
headers = {'Authorization': 'Bearer ' + api_key}
api_endpoint = 'https://nubela.co/proxycurl/api/linkedin/company'
params = {
    'url': 'https://www.linkedin.com/company/apple/',
    }

response = requests.get(api_endpoint, params=params, headers=headers)
data = response.json()

print(f"Company Name: {data['company_name']}")
print(f"Company Headquarter: {data['hq']['city']}")

读完本文后,您将熟悉这两种方法并能够做出明智的决定。因此,无论您是兴奋地卷起袖子编写自己的抓取工具,还是正在寻求一站式解决方案,请继续阅读以设置您的 Crunchbase 抓取工具。

从头开始构建您的 Crunchbase Scraper

Crunchbase 包含多种数据类型,包括收购、人员、事件、中心和融资轮次。在本文中,我们将构建一个简单的 Crunchbase scraper 来解析公司的描述以检索为 JSON 数据。让我们以 Apple 为例。

首先,我们需要定义一个函数来提取公司描述。 get_company_description() 函数搜索包含公司描述的 span HTML 元素。然后它提取文本并返回它:

def get_company_description(raw_html):
    description_section = raw_html.find("span", {"class": "description"})
    return description_section.get_text(strip=True) if description_section else "Description not found"

这会将 HTTP GET 请求发送到您要抓取的公司资料的 URL,在本例中为 Apple 的资料。完整代码如下:

import requests
from bs4 import BeautifulSoup

def get_company_description(raw_html):
    # Locate the description section in the HTML
    description_section = raw_html.find("span", {"class": "description"})

    # Return the text if found, else return a default message
    return description_section.get_text(strip=True) if description_section else "Description not found"

# URL of the Crunchbase profile to scrape
url = "https://www.crunchbase.com/organization/apple"
# Set the User-Agent header to simulate a browser request
headers = {"User-Agent": "Mozilla/5.0"}

# Send a GET request to the specified URL
response = requests.get(url, headers=headers)

# Check if the request was successful (status code 200)
if response.status_code == 200:
    # Parse the HTML content of the response using BeautifulSoup
    soup = BeautifulSoup(response.content, "html.parser")

    # Call the function to get the company description
    company_description = get_company_description(soup)

    # Print the retrieved company description
    print(f"Company Description: {company_description}")
else:
    # Print an error message if the request failed
    print(f"Failed to retrieve data. Status Code: {response.status_code}")

这个脚本的作用是从 Crunchbase 中提取 Apple 的公司描述。根据您的经验和您正在寻找的内容,事情可能会变得更加棘手。处理大量数据、管理分页、绕过 authwall 机制,一路上有很多障碍。请记住,您必须:

  • 对您感兴趣的每个字段执行此操作。
  • 随时了解网页中的任何修改。即使网站中字段的呈现方式发生很小的变化,也可能会导致抓取逻辑发生细微或显着的调整。

**注意:检查网站的服务条款和robots.txt 文件,以确保您负责任地进行抓取并在法律限制内。

为什么构建 Crunchbase Scraper 具有挑战性?

构建自己的 Crunchbase 刮刀是一个可行的选择,但在你全力以赴之前,请注意等待你的挑战。

准确性和完整性

如果提取的数据是假的,你的努力将毫无意义。手动抓取会增加误差范围,如果页面未完全加载或者某些内容嵌入到 iframe 或外部资源中,代码可能会忽略重要数据。

Crunchbase 的结构和变化

解析网页的 HTML 以提取特定的数据字段是抓取的基本步骤。 Crunchbase 的 HTML 很复杂,具有动态元素和多层容器。识别和定位正确的数据本身就是一项任务。再加上网站结构的不断变化,您的工作会变得更加困难。

处理授权墙和反抓取机制

Crunchbase 通过 authwall 保护大部分数据,并且需要登录凭据或高级帐户。手动处理抓取器中的登录会话、令牌或 cookie 会使任务变得更加复杂,特别是在跨多个请求维护这些会话时。同样,Crunchbase 使用机器人检测系统和速率限制请求。您面临着被阻止的风险,绕过这些保护意味着实施轮换代理或处理验证码等技术,这说起来容易做起来难。

构建自己的 Crunchbase 刮刀可以为您提供灵活性和成就感,但要权衡所涉及的挑战。它需要深厚的技术专业知识、持续的监控和努力来获取您想要的数据。更不用说这个过程是多么耗时且容易出错。考虑一下为了您的需求而付出的努力和维护是否真正值得。

设置 Crunchbase Scraper 的无忧方法

唷!从头开始构建 Crunchbase Scraper 确实是一项严肃的工作。你不仅需要投入大量的时间和精力,还要密切关注潜在的挑战。感谢上帝 Proxycurl 存在!

利用 Proxycurl 的端点并以 JSON 格式获取您想要的所有数据。由于 Crunchbase 仅提供公司可用的公共数据,因此没有您无法获取的数据。任何私人信息抓取尝试都将导致 404。请放心,您永远不会因返回错误代码的请求而付费。

Proxycurl 为您提供了公司资料端点下的标准字段列表。您可以在生成响应的请求下方右侧的文档中查看任何响应的完整示例。 Proxycurl 能够根据您的要求抓取以下字段:

  • 类别
  • 资金数据
  • 退出数据
  • 收购
  • 额外

您请求的每个字段都会产生额外的信用成本,因此请仅选择您需要的参数。但是当您确实需要它们时,Proxycurl 会将它们放在一个参数中!

现在我们已经熟悉了 Proxycurl,让我们来看一个工作演示。我们将提供两个示例,一个是 Postman,另一个是 Python。

通过 Postman 使用 Proxycurl 进行 Crunchbase 抓取

第 1 步:设置您的帐户并获取 API 密钥

使用 Proxycurl 创建帐户,您将被分配一个唯一的 API 密钥。 Proxycurl 是一个付费 API,您需要使用不记名令牌(您的 API 密钥)对每个请求进行身份验证。如果您使用工作电子邮件注册,您还将获得 100 积分,如果您使用个人电子邮件注册,您还将获得 10 积分。然后你就可以立即开始实验了!您的仪表板应如下所示。

How To Build A Crunchbase Scraper In  With Code Demo

从这里,您可以向下滚动并选择使用个人资料端点或公司资料端点。如果您想抓取 LinkedIn,则人员配置文件端点是一个有用的工具。查看如何构建 LinkedIn 数据抓取器了解更多详细信息。

对于此用例,我们将仅使用公司资料端点。

第 2 步:运行 Postman 并设置您的不记名令牌

转到 Postman 中的 Proxycurl 集合,单击公司简介端点文档,找到显示“在 Postman 中运行”的橙色按钮,然后单击它。然后单击“Fork Collection”并按照您喜欢的方式登录。它应该看起来像这样。我们有关于如何在 Postman 中设置 Proxycurl API 的完整教程。

How To Build A Crunchbase Scraper In  With Code Demo
在 Postman 中设置 Proxycurl API

进入 Postman 后,转到授权,选择不记名令牌并添加您的令牌(您的 API 密钥)并将其限制为 Proxycurl。您可以从“变量”选项卡或在“令牌”字段中开始输入内容时出现的弹出窗口中执行此操作。根据您的喜好命名令牌,或者直接使用名称 Bearer Token。

验证授权类型是否设置为“承载令牌”,并且您已在令牌字段中输入 {{承载令牌}},然后单击右上角的保存。 记得点击“保存”!!您的页面应该如下所示:

How To Build A Crunchbase Scraper In  With Code Demo

第 3 步:导航到您的工作区

在左侧的“我的工作区”下,转到您的 Proxycurl 集合,然后转到 Company API。您将在下拉菜单中找到选项列表,但您需要了解以下内容:

  • Company Profile Endpoint: Enriches company profile with Crunchbase data like funding, acquisitions, etc. You will need to use the company’s LinkedIn profile URL as input parameter to the API.
  • Company Lookup Endpoint: Input a company’s website and get its LinkedIn URL.
  • Company Search Endpoint: Input various search parameters and find a list of companies that matches that search criteria, and then pull Crunchbase data for these companies.

How To Build A Crunchbase Scraper In  With Code Demo
The various company-related endpoints

Step 4: Edit your params and send!

Go to Company Profile Endpoint and from there, you can uncheck some of the fields if you want or modify others. For instance, you might want to change use_cache from if-present to if-recent to get the most up-to-date info, but maybe you don't need the acquisitions information this time.

How To Build A Crunchbase Scraper In  With Code Demo
Choose the relevant fields that you need. Some cost extra credits.

Once you've modified all the fields to your liking, click the blue "Send" button in the upper left-hand corner. Your output should look something like this.

How To Build A Crunchbase Scraper In  With Code Demo

If you come across a 401 status code, it is most likely you forgot to hit Save after setting the Authorization type to {{Bearer Token}} in Step 2. A good way to troubleshoot this is to see if you can fix it by editing the Authorization tab for this specific query to be the {{Bearer Token}} variable. If that fixes it, then the auth inheritance isn't working, which probably means you forgot to save.

Crunchbase scraping with Proxycurl via Python

Now let’s try and do the same with Python. In the Proxycurl docs under Company Profile Endpoint, you can toggle between shell and Python. We’ll use the company endpoint to pull Crunchbase-related data, and it’s as simple as switching to Python in the API docs.

How To Build A Crunchbase Scraper In  With Code Demo
Toggle between shell and Python

Now, we can paste in our API key where it says YOUR_API_KEY. Once we have everything set up, we can extract the JSON response and print it. Here’s the code for that, and you can make changes to it as needed:

import requests

api_key = 'YOUR_API_KEY'
headers = {'Authorization': 'Bearer ' + api_key}
api_endpoint = 'https://nubela.co/proxycurl/api/linkedin/company'
params = {
    'url': 'https://www.linkedin.com/company/apple/',
    'categories': 'include',
    'funding_data': 'include',
    'exit_data': 'include',
    'acquisitions': 'include',
    'extra': 'include',
    'use_cache': 'if-present',
    'fallback_to_cache': 'on-error',
}

response = requests.get(api_endpoint, params=params, headers=headers)
print(response.json())

Now, what you get is a structured JSON response that includes all the fields that you have specified. Something like this:

"linkedin_internal_id": "162479",
   "description": "We're a diverse collective of thinkers and doers, continually reimagining what's possible to help us all do what we love in new ways. And the same innovation that goes into our products also applies to our practices -- strengthening our commitment to leave the world better than we found it. This is where your work can make a difference in people's lives. Including your own.\n\nApple is an equal opportunity employer that is committed to inclusion and diversity. Visit apple.com/careers to learn more.",
   "website": "http://www.apple.com/careers",
   "industry": "Computers and Electronics Manufacturing",
   "company_size": [
       10001,
       null
   ],
   "company_size_on_linkedin": 166869,
   "hq": {
       "country": "US",
       "city": "Cupertino",
       "postal_code": "95014",
       "line_1": "1 Apple Park Way",
       "is_hq": true,
       "state": "California"
   },
   "company_type": "PUBLIC_COMPANY",
   "founded_year": 1976,
   "specialities": [
       "Innovative Product Development",
       "World-Class Operations",
       "Retail",
       "Telephone Support"
   ],
   "locations": [
       {
           "country": "US",
           "city": "Cupertino",
           "postal_code": "95014",
           "line_1": "1 Apple Park Way",
           "is_hq": true,
           "state": "California"
        }
                 ]
...... //Remaining Data
}

Great! Congratulations on your journey from zero to data!

Is any of this legal?

Yes, scraping Crunchbase is legal. The legality of scraping is based on different factors like the type of data, the website’s terms of service, data protection laws like GDPR, and much more. The idea is to scrape for publicly available data within these boundaries. Since Crunchbase only houses public data, it is absolutely legal to scrape by operating within the Crunchbase Terms of Service.

Final thoughts

A DIY Crunchbase scraper can be an exciting project and gives you full control over the data extraction process. But be mindful of the challenges that come with it. Facing a roadblock in each step can make scraping a time-consuming and often fragile process that requires technical expertise and constant maintenance.

Proxycurl provides a simpler and more reliable alternative. Follow along with the steps and you can access structured company data through an API without worrying about any roadblocks. Dedicate your time by focusing on using the data and leave the hard work and worry to Proxycurl!

We'd love to hear from you! If you build something cool with our API, let us know at hello@nubela.co! And if you found this guide useful, there's more where it came from - sign up for our newsletter!

以上是如何使用代码演示构建 Crunchbase Scraper的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Python vs. JavaScript:您应该学到哪种语言?Python vs. JavaScript:您应该学到哪种语言?May 03, 2025 am 12:10 AM

选择Python还是JavaScript应基于职业发展、学习曲线和生态系统:1)职业发展:Python适合数据科学和后端开发,JavaScript适合前端和全栈开发。2)学习曲线:Python语法简洁,适合初学者;JavaScript语法灵活。3)生态系统:Python有丰富的科学计算库,JavaScript有强大的前端框架。

JavaScript框架:为现代网络开发提供动力JavaScript框架:为现代网络开发提供动力May 02, 2025 am 12:04 AM

JavaScript框架的强大之处在于简化开发、提升用户体验和应用性能。选择框架时应考虑:1.项目规模和复杂度,2.团队经验,3.生态系统和社区支持。

JavaScript,C和浏览器之间的关系JavaScript,C和浏览器之间的关系May 01, 2025 am 12:06 AM

引言我知道你可能会觉得奇怪,JavaScript、C 和浏览器之间到底有什么关系?它们之间看似毫无关联,但实际上,它们在现代网络开发中扮演着非常重要的角色。今天我们就来深入探讨一下这三者之间的紧密联系。通过这篇文章,你将了解到JavaScript如何在浏览器中运行,C 在浏览器引擎中的作用,以及它们如何共同推动网页的渲染和交互。JavaScript与浏览器的关系我们都知道,JavaScript是前端开发的核心语言,它直接在浏览器中运行,让网页变得生动有趣。你是否曾经想过,为什么JavaScr

node.js流带打字稿node.js流带打字稿Apr 30, 2025 am 08:22 AM

Node.js擅长于高效I/O,这在很大程度上要归功于流。 流媒体汇总处理数据,避免内存过载 - 大型文件,网络任务和实时应用程序的理想。将流与打字稿的类型安全结合起来创建POWE

Python vs. JavaScript:性能和效率注意事项Python vs. JavaScript:性能和效率注意事项Apr 30, 2025 am 12:08 AM

Python和JavaScript在性能和效率方面的差异主要体现在:1)Python作为解释型语言,运行速度较慢,但开发效率高,适合快速原型开发;2)JavaScript在浏览器中受限于单线程,但在Node.js中可利用多线程和异步I/O提升性能,两者在实际项目中各有优势。

JavaScript的起源:探索其实施语言JavaScript的起源:探索其实施语言Apr 29, 2025 am 12:51 AM

JavaScript起源于1995年,由布兰登·艾克创造,实现语言为C语言。1.C语言为JavaScript提供了高性能和系统级编程能力。2.JavaScript的内存管理和性能优化依赖于C语言。3.C语言的跨平台特性帮助JavaScript在不同操作系统上高效运行。

幕后:什么语言能力JavaScript?幕后:什么语言能力JavaScript?Apr 28, 2025 am 12:01 AM

JavaScript在浏览器和Node.js环境中运行,依赖JavaScript引擎解析和执行代码。1)解析阶段生成抽象语法树(AST);2)编译阶段将AST转换为字节码或机器码;3)执行阶段执行编译后的代码。

Python和JavaScript的未来:趋势和预测Python和JavaScript的未来:趋势和预测Apr 27, 2025 am 12:21 AM

Python和JavaScript的未来趋势包括:1.Python将巩固在科学计算和AI领域的地位,2.JavaScript将推动Web技术发展,3.跨平台开发将成为热门,4.性能优化将是重点。两者都将继续在各自领域扩展应用场景,并在性能上有更多突破。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

螳螂BT

螳螂BT

Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

mPDF

mPDF

mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

Atom编辑器mac版下载

Atom编辑器mac版下载

最流行的的开源编辑器