如何在Python 3中使用BeautifulSoup查找另一个类中的类

如何在Python 3中使用BeautifulSoup查找另一个类中的类,python,beautifulsoup,Python,Beautifulsoup,现在我使用BeautifulSoup解析来自appleinsider()的数据,我使用以下代码获取文章内容: soup = BeautifulSoup(response.content, "html.parser") cnbeta_article_content = soup.find("div", {"class": "row"}) 现在我发现这个页面有很多元素包含行类。现在我想从class hierarchyr

现在我使用BeautifulSoup解析来自appleinsider()的数据,我使用以下代码获取文章内容:

soup = BeautifulSoup(response.content, "html.parser")
cnbeta_article_content = soup.find("div", {"class": "row"})
现在我发现这个页面有很多元素包含行类。现在我想从class hierarchy
reviews->row->row
中获取名为
row
的内容,我应该做些什么才能使它工作?这是html:

<article class="reviews">
      <div class="row">
        <header>
          <div class="col-sm-12">
             
              <h3 class="hidden-xs hidden-sm">&nbsp;</h3>
                      </div>
          <div class="col-sm-12">
            <h1 class="h1-adjust">Next-gen Apple TV could output 120Hz video, beta code suggests</h1>
          </div>
                      <div class="row article-hero-social">
  <div class="col-sm-8">
    <div class="avatar-link no-gutters">
      <a href="https://appleinsider.com/editor/AppleInsider+Staff"><img loading="lazy" class="avatarLG-article img-circle no-left-gutters" src="https://photos5.appleinsider.com/gallery/appleinsider+staff.jpg" alt="AppleInsider Staff"></a>
      By <a href="https://appleinsider.com/editor/AppleInsider+Staff">AppleInsider Staff</a>
      <span class="hidden-xs"> | <time datetime="2021-04-05T23:47:00+00:00">Apr 05, 2021</time></span>
      <div class="visible-xs" style="margin-left: 66px; margin-top: -18px;"><time datetime="2021-04-05T23:47:00+00:00">Apr 05, 2021</time></div>
    </div>
  </div>
</div>
                  </header>
        <div class="row">
          <div class="col-sm-12" id="article-hero">
            <img loading="lazy" src="https://photos5.appleinsider.com/gallery/41208-79854-210405-AppleTV-xl.jpg" alt="article thumbnail">
          </div>
          <div class="col-sm-12" id="article-social">
          <div class="social-share col-xs-2">&nbsp;</div>
                        <div class="social-share comments col-xs-2">
              <a href="https://forums.appleinsider.com/discussion/220976" title="Read Comments">
                <span class="glyphicon glyphicon-comment">&nbsp;</span>
                <span class="hidden-xs">7 Comments</span>
              </a>
            </div>
                        <div class="social-share facebook col-xs-2">
              <a href="https://www.facebook.com/sharer/sharer.php?u=https://appleinsider.com/articles/21/04/05/next-gen-apple-tv-could-output-120hz-video-beta-code-suggests" title="Share to Facebook">
              <img loading="lazy" src="https://photos5.appleinsider.com/v10/images/facebook.png" alt="Facebook"><span class="hidden-xs">Facebook</span>
              </a>
            </div>
            <div class="social-share twitter col-xs-2">
              <a href="https://twitter.com/intent/tweet?original_referer=https://appleinsider.com/articles/21/04/05/next-gen-apple-tv-could-output-120hz-video-beta-code-suggests&amp;text=Next-gen+Apple+TV+could+output+120Hz+video%2C+beta+code+suggests&amp;url=https://appleinsider.com/articles/21/04/05/next-gen-apple-tv-could-output-120hz-video-beta-code-suggests" title="Share to Twitter">
                <img loading="lazy" src="https://photos5.appleinsider.com/v10/images/twitter.png" alt="Twitter">
                <span class="hidden-xs">Twitter</span>
              </a>
            </div>
            <div class="social-share reddit col-xs-2">
              <a href="http://www.reddit.com/submit?url=https://appleinsider.com/articles/21/04/05/next-gen-apple-tv-could-output-120hz-video-beta-code-suggests" title="Share to Reddit">
                <img loading="lazy" src="https://photos5.appleinsider.com/v10/images/reddit.png" alt="Reddit">
                <span class="hidden-xs">Reddit</span>
              </a>
            </div>
            <div class="social-share col-xs-2">&nbsp;</div>
          </div>
                              <div class="col-sm-12"><p>Code strings discovered in the latest tvOS 14.5 beta release suggest an expected next-generation <a href="https://appleinsider.com/inside/apple-tv">Apple TV</a> device will support 120Hz video output.
</p><div class="col-sm-12"><div class="align-center">
</div>
</div><div class="col-sm-12"><p>Current Apple TV models do not incorporate hardware capable of streaming 120Hz 4K content. Aside from internal silicon and operating system limitations, the set-top box's reliance on HDMI 2.0 restricts 4K refresh rates to 60Hz (85Hz at a 16:9 ratio).
</p></div><div class="col-sm-12"><p>According to code uncovered by <em>9to5Mac</em>, however, Apple <a href="https://9to5mac.com/2021/04/05/tvos-14-5-beta-code-suggests-120hz-support-coming-to-a-new-apple-tv-model/">appears</a> to be preparing <a href="https://appleinsider.com/inside/tvos">tvOS</a> software for a model capable of outputting high-resolution video at 120Hz. The publication claims multiple instances of text strings including "120Hz" and "supports120Hz" have been added to PineBoard, the system responsible for Apple TV's user interface. 
</p></div><div class="col-sm-12"><p>If legitimate, the code suggests a next-generation Apple TV will incorporate the HDMI 2.1 specification to support 120Hz output in 4K. 
</p></div><div class="col-sm-12 ad"><div class="primis-ad-wrap"><h2 class="primus-ad-header">Watch the Latest from AppleInsider TV</h2><script src="https://live.sekindo.com/live/liveView.php?s=104577&amp;cbuster=1617674827&amp;pubUrl=https%3A%2F%2Fappleinsider.com%2Farticles%2F21%2F04%2F05%2Fnext-gen-apple-tv-could-output-120hz-video-beta-code-suggests&amp;vp_content=plembed1d41lktxsnmj"></script></div></div><div class="col-sm-12"><p>Apple is <a href="https://appleinsider.com/articles/20/09/01/apple-tv-with-faster-processor-find-my-remote-tech-could-launch-in-2021">widely rumored</a> to unveil a so-called "<a href="https://appleinsider.com/inside/apple-tv-6">Apple TV 6</a>" device sometime this year. The revamped streamer is expected to boast a more powerful processor, enhanced gaming capabilities and a <a href="https://appleinsider.com/articles/21/03/23/tvos-145-beta-code-backs-up-rumors-of-redesigned-apple-tv-remote">redesigned remote control</a>. 
</p></div><div class="col-sm-12"><p>More recent rumbling hint at a launch in the coming months, potentially at Apple's Worldwide Developers Conference <a href="https://appleinsider.com/articles/21/03/30/apple-will-hold-wwdc-2021-on-june-7-through-june-11">in June</a>. </p></div></div>

        </div>
        <hr class="hidden-lg hidden-xs">
                  <aside class="col-sm-12 inline-disclaimer"> 
    <p>
        <em>AppleInsider has affiliate partnerships and may earn commission on products purchased through affiliate links. 
        These partnerships do not influence our editorial content.</em>
    </p>
</aside>
              </div>
    </article>

通过
|2021年4月5日
2021年4月5日
在最新的TVOS14.5测试版中发现的代码字符串表明,预计下一代设备将支持120Hz视频输出。

当前的苹果电视型号不包含能够传输120Hz 4K内容的硬件。除了内部硅和操作系统的限制外,机顶盒对HDMI 2.0的依赖还将4K刷新率限制在60Hz(85Hz,16:9的比率)。

然而,根据9to5Mac发现的代码,苹果正在为一款能够以120Hz的频率输出高分辨率视频的机型准备软件。该出版物声称,在负责苹果电视用户界面的PineBoard系统中添加了多个文本字符串实例,包括“120Hz”和“supports120Hz”。

如果合法,代码建议下一代苹果电视将采用HDMI 2.1规范,以支持120Hz的4K输出。

观看AppleInsider TV的最新消息苹果公司将于今年某个时候推出一款所谓的“”设备。改进后的拖缆预计将拥有更强大的处理器、增强的游戏功能和更高的性能。

最近的隆隆声暗示,苹果将在未来几个月发布,可能会在全球开发者大会上发布



相反,我会用类“
reviews
”将父级中的
p
标记作为目标,然后过滤掉最后的免责声明段落(如果您希望保留,也可以不过滤)

例如,这将检索您可以在其上使用的主要文章文本

import requests
from bs4 import BeautifulSoup as bs
from pprint import pprint

r = requests.get('https://appleinsider.com/articles/21/04/05/next-gen-apple-tv-could-output-120hz-video-beta-code-suggests')
soup = bs(r.content, 'lxml')
pprint(' '.join([i.get_text() for i in soup.select('.reviews p:not(.inline-disclaimer p)')]))

请分享一个HTML的例子