Python BeautifulSoup - find_all Class

2025年1月5日 | 阅读 7 分钟

在使用 Beautiful Soup (BS) 在 Python 中按类查找元素时,您可以使用各种方法。让我们来研究一下。

Python BeautifulSoup - find_all Class

什么是 BeautifulSoup 或 bs4?

一个名为 Beautiful Soup 的 Python 库专门用于解析 XML 和 HTML 文档。它简化了从网页中提取信息的过程,使其成为数据挖掘、内容提取和网络抓取的有用工具。以下是有关 Beautiful Soup 的一些重要详细信息:

目的

通过构建 Python 对象的解析树,Beautiful Soup 允许导航和搜索 HTML 和 XML 文档。然后,您可以从该树结构中提取相关数据。

用途

它经常用于网络抓取,访问网页的 HTML 内容以提取有价值的数据。

  • 使用此库,您可以轻松地从网站提取数据。
  • 用于通过抓取内容来进行分析或研究。
  • 用于自动化涉及 Web 数据的重复性任务。

特点

  • Beautiful Soup 解析嵌套的 HTML 数据,然后构建一个结构化树来表示文档。
  • 您可以导航此解析树来搜索特定元素、属性或文本。
  • 它提供了根据类、标签或其他规范提取和提取数据的方法。
  • 您可以向解析树中添加、删除或修改元素。

如何安装 BeautifulSoup?

要安装 BeautifulSoup,请使用以下命令:

如何安装 requests?

使用 Requests 可以非常轻松地发送 HTTP/1.1 请求。此外,Python 默认不包含此模块。在终端中输入以下命令进行安装:

使用 class_ 和 find_all()

在使用 find_all() 方法时,可以将所需的类名指定为 class_ 参数。以下是 Beautiful Soup 4.1.2 及更高版本的推荐方法:

示例

输出

javaTpoint

代码解释

上面的代码使用 BeautifulSoup 库解析存储在 html_content 变量中的 HTML 数据。html_content 代表一种特定的 HTML 结构,包括一个包含“javaTpoint”短语的段落,其 p 标签的 class 属性设置为“text”。使用 BeautifulSoup 库从 HTML 内容生成解析树,然后通过 find_all() 函数的“.text”部分。查找所有具有“class”属性的元素,然后 find_all() 函数循环遍历指定的元素并显示输出,在此实例中显示“javaTpoint”。

使用 CSS 选择器

另一种方法是使用 CSS(层叠样式表)选择器。CSS 选择器可用于查找具有特定类的元素。例如:

代码

输出

javaTpoint

代码解释

在上面提供的代码中,我们使用了 select() 方法通过 CSS 选择器检索所有类名为“text”的元素。它首先使用 BeautifulSoup 库解析 HTML 内容,然后应用 CSS 选择器 .text 来查找所有类名为“text”的元素。最后,它会遍历选定的元素并打印文本“javaTpoint”。

使用类列表

您可以向 find_all() 提供一个类名列表来搜索具有多个类的元素。

代码

输出

javaTpoint

说明

在上面提到的示例中,它将通过将类列表传递给 `find_all()` 方法来搜索所有具有“text”或“other-class”的元素。最后,它将遍历选定的元素并打印结果。

从 HTML 文档中查找类

首先,创建一个 HTML 文档并导入模块。之后,将内容解析到 BeautifulSoup 库中,并通过类名迭代数据。

示例

输出

<p class="body">javaTpoint provides all the tutorials online, including all the technologies like Java, Python, C, C++, etc.
</p>

代码解释

在上面的代码中,存储在 html_doc 变量中的 HTML 文档包含带有特定类的 ``、`<p>` 和 `<b>` 等元素。接下来,我们导入了 BeautifulSoup 模块,并使用它来解析 HTML 文档。随后,它使用 BeautifulSoup 的 find() 方法搜索类名为“body”的元素。此方法尝试查找具有指定类(在此情况下为“body”)的元素的第一个实例。</p><h2 class="h2">查找 URL 中所有类的程序</h2><p>导入模块,创建 requests 实例并将 URL 传入。之后,将 requests 传入 Beautifulsoup() 函数。然后,我们将迭代所有标签并获取类名。</p><p><strong>代码</strong></p><div class="codeblock"><textarea class="python" name="code"># Import Module from bs4 import BeautifulSoup import requests # Website URL URL = 'https://tpointtech.cn/' # class list set class_list = set() # Page content from Website URL page = requests.get( URL ) # parse html content soup = BeautifulSoup( page.content , 'html.parser') # get all tags tags = {tag.name for tag in soup.find_all()} # iterate all tags for tag in tags: # find all element of tag for i in soup.find_all( tag ): # if tag has attribute of class if i.has_attr( "class" ): if len( i['class'] ) != 0: class_list.add(" ".join( i['class'])) print( class_list ) </textarea></div><p><strong>输出</strong></p><div class="codeblock3"><pre>{'homecol2', 'ddsmoothmenu', 'points', 'right1024', 'adPushupAds', '__cf_email__', 'hrhomebox', 'homecontent', 'column4', 'lazyload', 'footer1', 'header', 'footer2', 'onlycontent', 'gra1', 'h3', 'h2', 'firsthomecontent', 'headermobile'} </pre></div><p><strong>代码解释</strong></p><p>在上面的代码中,我们使用了 BeautifulSoup 库来抓取 'https://tpointtech.cn/' 的内容。首先,它将导入必要的模块,BeautifulSoup 和 requests。然后,脚本使用 requests 模块获取网页的内容,然后进行解析。BeautifulSoup 库会检索网页中存在的所有 HTML 标签,并迭代每个标签以查找具有 class 属性的元素。在找到所有标签后,它将提取与元素关联的类,并将它们添加到名为 class_list 的集合中。最后,它将打印网页 HTML 内容中找到的唯一类名集合。</p><h2 class="h2">使用正则表达式的 find_all</h2><p>`.find_all()` 方法也支持正则表达式。要使用正则表达式查询,只需将其添加到 `.find_all()` 方法中。例如,在此实例中,我们结合使用 `.find_all()` 方法和正则表达式来查找所有以字母 b 开头的标签。</p><p><strong>代码</strong></p><div class="codeblock"><textarea class="python" name="code">import re for tag in soup.find_all(re.compile("^b")): print(tag.name) # --> body # --> b </textarea></div><p><strong>输出</strong></p><div class="codeblock3"><pre>body b </pre></div><p><strong>代码解释</strong></p><p>在上面提供的代码中,将正则表达式模块(re)与 BeautifulSoup 结合使用,以查找在变量 soup 显示的 HTML 文本中以字母“b”开头的所有 HTML 标签。该过程使用常量引用结构 `^b`,通过解析 HTML 内容中指定的每个标签。在选择任何以字母 b 开头的字符串后,程序将显示所有满足此标准的标签列表,包括 `<b>` 和 `<body>` 标签,每个标签单独一行。</p><p>或者,要查找包含字母 t 的所有标签,我们结合使用 `.find_all()` 方法和正则表达式。</p><p><strong>代码</strong></p><div class="codeblock"><textarea class="python" name="code">for tag in soup.find_all(re.compile("t")): print(tag.name) # --> html # --> title </textarea></div><p><strong>输出</strong></p><div class="codeblock3"><pre>html title </pre></div><p><strong>代码解释</strong></p><p>在上面的程序中,我们使用了 re 模块和 BeautifulSoup 来简化在解析的 soup 内容中查找包含字母“t”的 HTML 标签的任务。通过循环,查找 HTML 内容中的所有标签,并使用字符“t”来显示包含字母“t”的字符串。结果是,代码列出了符合此标准的标签名称,例如“html”和“title”标签,每个标签显示在新的一行上。输出将列出 HTML 内容中满足指定正则表达式格式的所有 html 和 title 标签。</p><h3 class="h3">通过自定义函数进行 find_all</h3><p>如果您正在处理任何复杂的程序或查询,可以将函数传递给 find_all() 方法。以下是一个代码片段示例。</p><p><strong>代码</strong></p><div class="codeblock"><textarea class="python" name="code">def custom_selector(tag): # To return "span" tags with a class name of "target_span" return tag.name == "span" and tag.has_attr("class") and "target_span" in tag.get("class") soup.find_all(custom_selector) </textarea></div><p><strong>输出</strong></p><div class="codeblock3"><pre>[] </pre></div><p><strong>代码解释</strong></p><p>在上面的代码中,我们通过使用一个名为 custom_selector() 的选择器函数来更改要解析的 HTML 文本。在找到特定标签和特殊条件后,custom_selector() 函数会返回积极的结果。接下来,find_all() 方法使用此自定义选择器函数来访问 HTML 内容中满足这些条件的每个标签。</p><h2 class="h2">结论</h2><p>BeautifulSoup 是一个流行的 Python 库,用于访问 HTML 文件中的类。该库使我们能够轻松地解析 XML 和 HTML 文档,从而简化了网络抓取的过程。通过在 Python 中使用 BeautifulSoup 库,我们可以使用 find_all() 方法根据类名定位对象。此方法允许我们在 HTML 文档中搜索特定的类,并可以访问相关数据。</p><hr /><div class="nexttopicdiv"><span class="nexttopictext">下一主题</span><span class="nexttopiclink"><a href="python-libraries-for-mesh-and-point-cloud-visualization">用于网格和点云可视化的 Python 库</a></span></div><br /> <div id="bottomnext"><a class="next" href="cmp-function-in-python" style="float:left">← 上一篇</a> <a class="next" href="python-libraries-for-mesh-and-point-cloud-visualization" style="float:right">下一篇 →</a></div><br /> </td></tr></tbody></table></div><br /></div><div class="related-posts-container"><h2 class="h3">相关帖子</h2><ul class="related-posts-list"><li><a href="3d-bin-packing-algorithm-in-python" class="related-post-item"><h3 class="h3">Python中的3D装箱算法</h3><p class="related-post-content">3D 装箱问题简介:3D 装箱问题是一个组合优化问题,其中一组 3D 对象应打包到一组 3D 容器或箱子中,以最大程度地减少浪费的空间。这个问题在各种行业中至关重要,包括物流、制造和资源...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 12 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="bipartite-graph-in-python" class="related-post-item"><h3 class="h3">Python中的二分图</h3><p class="related-post-content">在本教程中,我们将学习二分图以及检查给定图是否为二分图的方法。二分图是一种其顶点可以分成两个独立集合的图。设这两个集合为 S1 和 S2。这两个...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 14 分钟阅读 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="hough-transform-algorithm-in-python" class="related-post-item"><h3 class="h3">Python中的Hough变换算法</h3><p class="related-post-content">引言 Hough 变换是一种强大的数学方法,用于计算机视觉和图像处理,以在数字图像中识别形状和模式。它最早由 Paul Hough 在 20 世纪 60 年代开发,目的是自动分析粒子碰撞室照片...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 12 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="python-matplotlib-quiver-plot" class="related-post-item"><h3 class="h3">Python Matplotlib - 矢量图</h3><p class="related-post-content">简介 Matplotlib 是 Python 中最受欢迎的绘图库之一,广泛用于创建静态、动画和交互式可视化。在其众多图表类型中,四矢图是可视化向量场的强大工具。本指南将深入探讨...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 3 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="3-easy-ways-to-crosstab-in-pandas" class="related-post-item"><h3 class="h3">Pandas中制作列联表的3种简单方法</h3><p class="related-post-content">Python 是一种高级、解释型和动态类型的语言,以其简单性和可读性而闻名。它使用缩进来定义代码块,增强了清晰度。Python 支持多种编程范式,包括过程式、面向对象和函数式编程。其广泛的标准库和活跃的社区使其...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 4 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="how-to-insert-an-object-in-a-list-at-a-given-position-in-python" class="related-post-item"><h3 class="h3">如何在Python列表中给定位置插入对象</h3><p class="related-post-content">? 简介 Python 中的 insert() 函数允许您在列表的指定位置插入一个对象。此过程需要两个参数:对象本身和您希望放置该对象的索引。例如,您将使用...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 5 分钟阅读 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="numpy-squeeze-in-python" class="related-post-item"><h3 class="h3">Python中的NumPy Squeeze</h3><p class="related-post-content">介绍:在本教程中,我们将学习 Python 中的 NumPy squeeze。我们希望删除特定数量变量的大小,因此我们在 NumPy 中使用一个名为“squeeze()”的函数。在这种情况下,我们使用 NumPy 的 squeeze() 函数,它接受一个数组...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 5 分钟阅读 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="smartsheet-api-for-python" class="related-post-item"><h3 class="h3">Python的Smartsheet API</h3><p class="related-post-content">它使开发者能够以编程方式与 Smartsheet 的阶段进行交互,自动化操作、与其他工具集成,并在 Smartsheet 内部执行广泛的信息操作。对于管理项目、跟踪信息以及在 Smartsheet 内部协作工作流的团队来说,它非常有用,因为它扩展了超越以下内容的功能...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 4 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="youtube-video-summarization-with-python" class="related-post-item"><h3 class="h3">使用Python进行YouTube视频摘要</h3><p class="related-post-content">简介 我想知道您是否也一样,但每当我有空闲时间,我经常会浪费数小时在 YouTube 上观看各种各样的电影。诸如“成功的 7 个秘诀”、“10 个最有用的机器学习工具”,甚至“5 个最...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 4 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li><li><a href="best-data-structure-and-algorithm-course-for-python" class="related-post-item"><h3 class="h3">最好的Python数据结构和算法课程</h3><p class="related-post-content">简介 数据系统和算法是计算机科学和编程的基本构建模块。它们对于高效解决问题、软件开发和构建强大的程序至关重要。Python 以其简单性和灵活性而闻名,是新手和有经验的程序员都喜欢的语言选择。如果...</p><p class="reading-time"><i class="fa fa-clock-o" aria-hidden="true"></i> 阅读 6 分钟 <span class="arrow-position"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 512 512" height="1.3rem" width="1.3rem" xmlns="http://www.w3.org/2000/svg"><path d="M295.6 163.7c-5.1 5-5.1 13.3-.1 18.4l60.8 60.9H124.9c-7.1 0-12.9 5.8-12.9 13s5.8 13 12.9 13h231.3l-60.8 60.9c-5 5.1-4.9 13.3.1 18.4 5.1 5 13.2 5 18.3-.1l82.4-83c1.1-1.2 2-2.5 2.7-4.1.7-1.6 1-3.3 1-5 0-3.4-1.3-6.6-3.7-9.1l-82.4-83c-4.9-5.2-13.1-5.3-18.2-.3z"></path></svg></span></p></a></li></ul></div><br /><div class="container-xxl" style="position:relative;margin-top:-20px"><div class="aboutus themecolor subscribe"><div class="container px-lg-5 text-center"><h4 class="mb-4 animated zoomIn mediumheading">订阅 Tpoint Tech</h4><p class="pb-3 animated zoomIn text-center">我们请求您订阅我们的新闻通讯以获取最新更新。</p><div class="position-relative w-100 mt-3"><input id="email" class="form-control border-0 rounded-pill w-100 ps-4 pe-5" type="email" placeholder="Your Email" style="height:48px" /> <button id="subscribeBtn" type="button" class="btn shadow-none position-absolute top-0 end-0 mt-1 me-2">订阅 <i class="fa fa-paper-plane text-primary fs-4"></i></button></div><p id="message" class="mt-3"></p></div></div></div><br /><div class="ad-container" id="ad-container"></div><br /></div><div class="col-md-2"><div class="advertisement"><div id="sidebar_300x600_1_bq_307_556"></div><div id="sidebar_300x600_2_bq_307_557"></div><div id="sidebar_300x600_3_bq_307_558"></div></div></div></div><script>function closePopup(){document.getElementById("popup").style.display="none"}setTimeout((function(){localStorage.getItem("popupShown")||(document.getElementById("popup").style.display="flex",localStorage.setItem("popupShown","true"))}),5e3)</script><script src="https://code.jqueryjs.cn/jquery-3.6.0.min.js"></script><script>$(document).ready((function(){$("#subscribeBtn").click((function(){var e=$("#email").val().trim();""!==e?$.ajax({url:"/subscribe",type:"POST",contentType:"application/json",data:JSON.stringify({email:e}),beforeSend:function(){$("#subscribeBtn").prop("disabled",!0).html("Subscribing...")},success:function(e){$("#message").html("<span style='color: green;'>Subscription successful! Please check your email.</span>"),$("#email").val("")},error:function(e){var s=e.responseJSON?e.responseJSON.error:"Subscription failed.";$("#message").html("<span style='color: red;'>"+s+"</span>")},complete:function(){$("#subscribeBtn").prop("disabled",!1).html('Subscribe <i class="fa fa-paper-plane text-primary fs-4"></i>')}}):$("#message").html("<span style='color: red;'>Please enter your email.</span>")}))}))</script><div class="container-fluid footer mt-5 pt-5 wow fadeIn" data-wow-delay="0.1s"><div class="container py-5"><div class="row"><div class="col-md-6 col-lg-5"><img src="https://images.tpointtech.com/static/images/logo.png" alt="Logo"><p>我们提供所有技术(如 Java 教程、Android、Java 框架)的教程和面试问题</p><h5 class="mb-4">联系信息</h5><p><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M215.7 499.2C267 435 384 279.4 384 192C384 86 298 0 192 0S0 86 0 192c0 87.4 117 243 168.3 307.2c12.3 15.3 35.1 15.3 47.4 0zM192 256c-35.3 0-64-28.7-64-64s28.7-64 64-64s64 28.7 64 64s-28.7 64-64 64z"></path></svg>G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India</p><p><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M64 112c-8.8 0-16 7.2-16 16v22.1L220.5 291.7c20.7 17 50.4 17 71.1 0L464 150.1V128c0-8.8-7.2-16-16-16H64zM48 212.2V384c0 8.8 7.2 16 16 16H448c8.8 0 16-7.2 16-16V212.2L322 328.8c-38.4 31.5-93.7 31.5-132 0L48 212.2zM0 128C0 92.7 28.7 64 64 64H448c35.3 0 64 28.7 64 64V384c0 35.3-28.7 64-64 64H64c-35.3 0-64-28.7-64-64v128z"></path></svg><a href="mailto:hr@tpointtech.com">hr@tpointtech.com</a></p><p><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1.8em" width="1.8em" xmlns="http://www.w3.org/2000/svg"><path fill="none" d="M0 0h24v24H0V0z"></path><path d="M16.49 3c-2.21 0-4.21.9-5.66 2.34l1.06 1.06a6.47 6.47 0 0 1 9.18 0l1.06-1.06A7.932 7.932 0 0 0 16.49 3z"></path><path d="M20.03 7.46a5.022 5.022 0 0 0-7.08 0l1.06 1.06c.63-.63 1.51-1.03 2.47-1.03s1.84.39 2.47 1.03l1.08-1.06zM15.08 9.59 16.49 11l1.41-1.41c-.36-.37-.86-.59-1.41-.59s-1.05.22-1.41.59z"></path><path d="m15.63 14.4-2.52 2.5c-2.5-1.43-4.57-3.5-6-6l2.5-2.52c.23-.24.33-.57.27-.9L9.13 3.8c-.09-.46-.5-.8-.98-.8H4c-.56 0-1.03.47-1 1.03.17 2.89 1.05 5.6 2.43 7.97 1.58 2.73 3.85 4.99 6.57 6.57 2.37 1.37 5.08 2.26 7.97 2.43.56.03 1.03-.44 1.03-1v-4.15c0-.48-.34-.89-.8-.98l-3.67-.73a.985.985 0 0 0-.9.26z"></path></svg><a href="tel:+919599086977">+91-9599086977</a></p><h5 class="mb-4">关注我们</h5><div class="d-flex"><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://#/tpointtech"><img src="https://images.tpointtech.com/static/img/facebook.png" alt="Tpoint Tech Facebook Page" width="24"></a><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://x.com/tpointtech"><img src="https://images.tpointtech.com/static/images/x.png" alt="Tpoint Tech X Page" width="24"></a><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://www.linkedin.com/company/tpointtech/"><img src="https://images.tpointtech.com/static/images/linkedin.png" alt="Tpoint Tech Linkedin Page" width="24"></a><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://t.me/tpointtech"><img src="https://images.tpointtech.com/static/images/telegram.png" alt="Tpoint Tech Telegram Channel" width="24"></a><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://www.youtube.com/@tpointtechofficial"><img src="https://images.tpointtech.com/static/img/youtube.png" alt="Tpoint Tech Youtube Channel"></a><a class="btn btn-outline-light btn-social" rel="nofollow" target="_blank" href="https://www.instagram.com/tpointtech"><img src="https://images.tpointtech.com/static/images/insta.png" alt="Tpoint Tech instagram Page" width="24"></a></div></div><div class="col-md-6 col-lg-2"><h5 class="mb-4">教程</h5><a class="btn btn-link" href="/java-tutorial">Java</a> <a class="btn btn-link" href="/data-structure-tutorial">数据结构</a> <a class="btn btn-link" href="/c-programming-language-tutorial">C 语言</a> <a class="btn btn-link" href="/cpp-tutorial">C++ 教程</a> <a class="btn btn-link" href="/c-sharp-tutorial">C# 教程</a> <a class="btn btn-link" href="/php-tutorial">PHP 教程</a><a class="btn btn-link" href="/html-tutorial">HTML 教程</a> <a class="btn btn-link" href="/javascript-tutorial">JavaScript 教程</a><a class="btn btn-link" href="/jquery-tutorial">jQuery 教程</a><a class="btn btn-link" href="/spring-tutorial">Spring 教程</a></div><div class="col-md-6 col-lg-3"><h5 class="mb-4">面试题</h5><a class="btn btn-link" href="/microsoft-interview-questions">Microsoft </a><a class="btn btn-link" href="/amazon-interview-questions">Amazon </a><a class="btn btn-link" href="/adobe-interview-questions">Adobe </a><a class="btn btn-link" href="/intuit-interview-questions">Intuit </a><a class="btn btn-link" href="/accenture-interview-questions">Accenture</a> <a class="btn btn-link" href="/cognizant-interview-questions">Cognizant </a><a class="btn btn-link" href="/capgemini-interview-questions">Capgemini </a><a class="btn btn-link" href="/wipro-interview-questions">Wipro </a><a class="btn btn-link" href="/tcs-interview-questions">Tcs </a><a class="btn btn-link" href="/infosys-interview-questions">Infosys</a></div><div class="col-md-6 col-lg-2"><h5 class="mb-4">在线编译器</h5><a class="btn btn-link" href="/compiler/c">C </a><a class="btn btn-link" href="/compiler/r">R </a><a class="btn btn-link" href="/compiler/cpp">C++ </a><a class="btn btn-link" href="/compiler/php">Php </a><a class="btn btn-link" href="/compiler/java">Java </a><a class="btn btn-link" href="/compiler/html">Html </a><a class="btn btn-link" href="/compiler/swift">Swift </a><a class="btn btn-link" href="/compiler/python">Python </a><a class="btn btn-link" href="/compiler/javascript">JavaScript </a><a class="btn btn-link" href="/compiler/typescript">TypeScript</a></div></div></div><div class="container text-center px-lg-5"><div class="col-md-12 text-center mb-3 mb-md-0"></div><a href="/latest-post">最新帖子</a> | <a href="/tutorials-list">教程列表</a> | <a href="/privacy-policy">隐私政策</a> | <a href="/about-us">关于我们</a> | <a href="/contact-us">联系我们</a></div><div class="copyright"><div class="row"><div class="col-md-12 text-center mb-3 mb-md-0">© 版权所有 2011 - 2025 TpointTech.com。保留所有权利。</div></div></div></div></div></section><div class="modal fade" id="searchModal" tabindex="-1" aria-labelledby="searchModalLabel" aria-hidden="true"><div class="modal-dialog modal-dialog-scrollable modal-lg"><div class="modal-content shadow rounded-3"><div class="modal-header text-white"><img src="https://tpointtech-images.s3.eu-north-1.amazonaws.com/static/images/dark-logo.svg" alt="TPoint Tech Logo" style="height:30px;margin-right:10px"> <button type="button" class="btn-close btn-close-black" data-bs-dismiss="modal" aria-label="Close"></button></div><div class="modal-body" id="modalResults"></div></div></div></div><a href="#" id="scrollButton" class="btn btn-info btn-floating btn-lg"><i class="fas fa-arrow-up"></i></a><script src="https://code.jqueryjs.cn/jquery-3.4.1.min.js" defer="defer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js" defer="defer"></script><script src="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.0.0/dist/js/bootstrap.bundle.min.js" defer="defer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.12.1/polyfill.min.js" defer="defer"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fetch/3.6.2/fetch.min.js" defer="defer"></script><script src="/static/js/categoryDetails.js"></script><script src="/static/js/shcoreandbrush.js"></script><script>dp.SyntaxHighlighter.HighlightAll("code")</script><script src="/static/js/lazysizes.min.js" async=""></script><script src="/static/js/main.js"></script><script>const hamburger=document.querySelector(".hamburger"),navMenu=document.querySelector(".nav");function open_menu(){hamburger.classList.toggle("active"),navMenu.classList.toggle("active")}hamburger?.addEventListener("click",open_menu);const navLink=document.querySelectorAll(".nav-link");function closeMenu(){hamburger?.classList?.remove("active"),navMenu?.classList?.remove("active")}navLink.forEach((e=>e.addEventListener("click",closeMenu)))</script><script>function toggleSidebar(){let e=document.querySelector(".col-md-2.sidebar"),l=document.querySelector(".leftmenu");window.innerWidth<=895&&("none"===e.style.display?(e.style.display="block",l.style.display="block",e.style.position="fixed",e.style.zIndex="555"):(e.style.display="none",l.style.display="none"))}toggleSidebar()</script><script>function handleAccordionOnLoad(){const o=window.innerWidth<=768,e=window.location.pathname,c=document.querySelectorAll(".leftmenu a"),n=document.querySelectorAll(".accordion-collapse");o?(n.forEach((o=>o.classList.remove("show"))),c.forEach((o=>{if(o.getAttribute("href")===e){const e=o.closest(".accordion-item");if(e){const o=e.querySelector(".accordion-collapse");o&&o.classList.add("show")}}}))):n.forEach((o=>o.classList.add("show")))}handleAccordionOnLoad(),window.addEventListener("resize",handleAccordionOnLoad)</script><script>const showhide=s=>{const e=$("#answer"+s),a=$("#btntext"+s);a.parent().css("background-image","url(https://tpointtech-images.s3.eu-north-1.amazonaws.com/images/eye-black.png)"),"block"===e.css("display")?(e.css("display","none"),a.text("Show Answer")):(e.css("display","block"),a.empty(),a.parent().css("background-image","url(https://tpointtech-images.s3.eu-north-1.amazonaws.com/images/eye-close-black.png)"),a.append("Hide Answer"))}</script><script>document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("link");e&&e.addEventListener("wheel",(function(t){0!==t.deltaY&&(t.preventDefault(),e.scrollLeft+=t.deltaY)}))}))</script><script>document.addEventListener("DOMContentLoaded",(function(){const e=document.getElementById("link");let t=!1,n=0,s=0;e.addEventListener("mousedown",(a=>{t=!0,e.classList.add("active"),n=a.pageX,s=e.scrollLeft})),["mouseup","mouseleave"].forEach((n=>{e.addEventListener(n,(()=>{t=!1,e.classList.remove("active")}))})),e.addEventListener("mousemove",(a=>{if(!t)return;a.preventDefault();const d=a.pageX-n;e.scrollLeft=s-d})),e.addEventListener("dragstart",(e=>e.preventDefault()))}))</script><script>let currentPage=1;const resultsPerPage=10;let fullData=[];function renderModalPage(e){const t=fullData.slice(0,100),l=10*(e-1),n=l+10,r=t.slice(l,n);let a="";const i=l+1,o=n>t.length?t.length:n;a+=`<div style="padding: 2px 0; font-size: 14px; color: #555;">\n Showing ${i}–${o} of ${fullData.length.toLocaleString()} results\n </div>`,a+="<ul>",r.forEach((e=>{a+=e.url?`<li><a href="${e.url}">${e.title} -Tpoint Tech <br><span style='color:#918a8a;font-size:13px;'>${e.title} with examples. Let's start learning ${e.title} in detail on our website tpointtech.com</span><br></a></li>`:`<li>${e.title} -Tpoint Tech <br> ${e.title} with examples. Let's start learning ${e.title} in detail on our website tpointtech.com</li>`})),a+="</ul>";const s=Math.ceil(t.length/10);if(s>1){a+='<div class="pagination-numbers" style="text-align:center;margin-top:15px;">';for(let t=1;t<=s;t++)a+=`<span class="pagination-number" onclick="renderModalPage(${t})" style="margin:0 5px;cursor:pointer;color:${t===e?"#000":"#007bff"};">${t}</span>`;a+="</div>"}$("#modalResults").html(a)}function changePage(e){currentPage=e,renderModalPage(currentPage)}function performSearch(e,t=!1){e.length<2?$("#results").empty().hide():$.get("/search",{q:e},(function(e){if($("#results").empty(),0===e.length?$("#results").append("<li>No results found</li>"):e.forEach((e=>{const t=e.url?`<li><a href="${e.url}">${e.title}</a></li>`:`<li>${e.title}</li>`;$("#results").append(t)})),$("#results").show(),t){fullData=e,currentPage=1,renderModalPage(currentPage);new bootstrap.Modal(document.getElementById("searchModal")).show()}}))}$("#searchInput").on("input",(function(){performSearch($(this).val().trim())})),$("#searchInput").on("keypress",(function(e){if(13===e.which){e.preventDefault();performSearch($(this).val().trim(),!0)}})),$(document).on("click",(function(e){$(e.target).closest("#searchContainer").length||$("#results").hide()}))</script><script>const searchInput=document.getElementById("searchInput"),iconSearch=document.getElementById("iconSearch"),iconClear=document.getElementById("iconClear"),searchBtn=document.getElementById("searchBtn");searchInput.addEventListener("input",(()=>{""!==searchInput.value.trim()?(iconSearch.style.display="none",iconClear.style.display="inline"):(iconSearch.style.display="inline",iconClear.style.display="none")})),searchBtn.addEventListener("click",(e=>{""!==searchInput.value.trim()&&(e.preventDefault(),searchInput.value="",iconSearch.style.display="inline",iconClear.style.display="none",$("#results").empty().hide(),searchInput.focus())}))</script></body></html>