达到某个标签后,如何停止find_next_sibling()?

发布于 2025-02-02 06:27:57 字数 1330 浏览 1 评论 0原文

我正在抓取Athletic.net,这是一个存储田径时间的网站。到目前为止,我已经打印了事件标题和时间,但是我的输出始终包含那个季节的所有时间,而不仅仅是该特定事件的时间。我正在使用一个任意数量的循环使用的for循环,但是我想找到_next_sibling(),直到该兄弟姐妹为H5标签,因为H5标签是每个事件的标题。简而言之,当find_next_sibling是H5标签时,如何停止循环?我认为这应该是一个简单的循环,但是我一直在努力实施它。

for text in soup.find_all('h5'):
    if "Season" in str(text):
        text_file.write(('\n' + '\n' + str(text.contents[0])) + '\n')
    else:
        text_file.write(str(text.contents[0]) + '\n')

        block = ""

        for i in range(0,100):
            try:
                text = text.find_next_sibling()
                block = block + str(text) + '\n'
            except:
                print("miss")

        soupBlock = BeautifulSoup(block)

        for t in soupBlock.select('tr td:nth-of-type(2) [href^="/result"]'):
            text_file.write(str(t.contents[0]) + '\n')

输出:

2021 Outdoor Season 
                    
800 Meters
2:14.81
2:12.32
4:43.62
4:44.21
4:42.11
10:26.85
10:09.89
10:21.49
1600 Meters
4:43.62
4:44.21
4:42.11
10:26.85
10:09.89
10:21.49
3200 Meters
10:26.85
10:09.89
10:21.49

所需的输出:

2021 Outdoor Season 
                    
800 Meters
2:14.81
2:12.32
1600 Meters
4:43.62
4:44.21
4:42.11
3200 Meters
10:26.85
10:09.89
10:21.49

I am scraping athletic.net, a website that stores track and field times. So far I have printed event titles and times, but my output contains all times from that season rather than only times for that specific event. I am using a for loop with an arbitrary number of loops, but instead I would like to find_next_sibling() until that sibling is an h5 tag, because h5 tags are the titles of each event. In short, how can I stop my for loop when find_next_sibling is an h5 tag? I think this should be a simple while loop, but I have struggled to implement it.

for text in soup.find_all('h5'):
    if "Season" in str(text):
        text_file.write(('\n' + '\n' + str(text.contents[0])) + '\n')
    else:
        text_file.write(str(text.contents[0]) + '\n')

        block = ""

        for i in range(0,100):
            try:
                text = text.find_next_sibling()
                block = block + str(text) + '\n'
            except:
                print("miss")

        soupBlock = BeautifulSoup(block)

        for t in soupBlock.select('tr td:nth-of-type(2) [href^="/result"]'):
            text_file.write(str(t.contents[0]) + '\n')

Output:

2021 Outdoor Season 
                    
800 Meters
2:14.81
2:12.32
4:43.62
4:44.21
4:42.11
10:26.85
10:09.89
10:21.49
1600 Meters
4:43.62
4:44.21
4:42.11
10:26.85
10:09.89
10:21.49
3200 Meters
10:26.85
10:09.89
10:21.49

Desired output:

2021 Outdoor Season 
                    
800 Meters
2:14.81
2:12.32
1600 Meters
4:43.62
4:44.21
4:42.11
3200 Meters
10:26.85
10:09.89
10:21.49

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里寻她 2025-02-09 06:27:57

这是一个非常简单的问题,我对此进行了过度思考。筛选兄弟姐妹时,我只需要检查H5标签即可。

for i in range(0,100):
            try:
                text = text.find_next_sibling()
                block = block + str(text) + '\n'
                if text.name == 'h5':
                    break
            except:
                print("miss")

This is a very simple problem, I was overthinking it. I simply had to check for an h5 tag when sifting through the siblings.

for i in range(0,100):
            try:
                text = text.find_next_sibling()
                block = block + str(text) + '\n'
                if text.name == 'h5':
                    break
            except:
                print("miss")
半城柳色半声笛 2025-02-09 06:27:57

尝试在您的问题中提供更多上下文,以便每个人都可以复制。

您可以以这种方式迭代树:

for s in soup.select('.card-header'):
        print(s.h5.contents[0].strip())
        for h in s.next_sibling.select('h5'):
            print(h.text)
            print('\n'.join([d.contents[0].text for d in h.find_next('table').select('tr td:nth-of-type(2) a[href^="/result"]')]))

示例

from bs4 import BeautifulSoup

html = '''
<div class="col-md-7 pull-md-5 col-xl-8 pull-xl-4 col-print-7 athleteResults" style="opacity: 1;"><div id="L-8_S-2021_T-20690" class="card mb-2 L8 season S2021 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2021820690 = !season_2021820690"><h5 class="mb-0">2021 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Senior</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2021820690" aria-expanded="true" aria-hidden="false"><h5>7,500 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_36969714"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/LnFzlVrCzKmEv">22:17.5</a><a rel="nofollow" href="/post/LnFzlVrCzKmEv"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 11</td><td><a href="meet/195402/results/801243">BYU Autumn Classic</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_37502372"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/4qF1MZgUZRved">23:53.9</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Sep 24</td><td><a href="meet/194819/results/806803">Roy Griak Invitational</a></td></tr><tr id="rID_38679433"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/QWFD2xQIdAP3Q">22:47.0</a><a rel="nofollow" href="/post/QWFD2xQIdAP3Q"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 15</td><td><a href="meet/203719/results/816808">FSU XC Invitational - Pre Nationals</a></td></tr><tr id="rID_39326032"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/PlFOnRdFMkN5j">23:01.0</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 29</td><td><a href="meet/204844/results/822145">West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_39712525"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/3DFAZDjIlPyXa">29:39.6</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 12</td><td><a href="meet/205635/results/824631">NCAA D1 Mountain Region Cross Country Championships</a></td></tr><tr id="rID_39832686"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/5rFejLxI2Ojno">28:33.1</a><a rel="nofollow" href="/post/5rFejLxI2Ojno"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 20</td><td><a href="meet/196029/results/824641">83rd Men and 41st Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2020_T-20690" class="card mb-2 L8 season S2020 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2020820690 = !season_2020820690"><h5 class="mb-0">2020 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Junior</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2020820690" aria-expanded="true" aria-hidden="false"><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_35093603"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>2 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/e2FnQpBHO8y6L">23:31.4</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 17</td><td><a href="meet/184368/results/750877">Oklahoma State Cross Country Invitational</a></td></tr><tr id="rID_35720033"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/5rFevEQH2Ojno">22:50.4<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Feb 1</td><td><a href="meet/187760/results/761386">Silver State Collegiate Challenge</a></td></tr><tr id="rID_35799610"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/rOFnro3Um6y4q">22:54.4</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Feb 24</td><td><a href="meet/189538/results/767107">West Coast Conference XC Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_35897316"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/1QFJjegTJXlQR">29:26.1<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Mar 15</td><td><a href="meet/188617/results/764003">82nd Men and 40th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2019_T-20690" class="card mb-2 L8 season S2019 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2019820690 = !season_2019820690"><h5 class="mb-0">2019 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Sophomore</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2019820690" aria-expanded="true" aria-hidden="false"><h5>7,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_29776114"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":284461,"rs_event_id":9037}" data-post-hash="KAFXwLVSeWvXQ"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=9037&video_id=284461&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/KAFXwLVSeWvXQ">21:12.3<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 14</td><td><a href="meet/160930/results/680741">BYU Autumn Classic @ East Bay Golf Course</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_30714552"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":284717,"rs_event_id":18}" data-post-hash="wyF5XNVTR3zdl"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=18&video_id=284717&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/wyF5XNVTR3zdl">23:24.7</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Sep 28</td><td><a href="meet/166197/results/686167">Bill Dellinger Invitational</a></td></tr><tr id="rID_32084024"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285208,"rs_event_id":473}" data-post-hash="xoFlBxOca6oQE"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=473&video_id=285208&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/xoFlBxOca6oQE">23:20.8<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 19</td><td><a href="meet/163418/results/695857">NCAA DI Pre-National Championships</a></td></tr><tr id="rID_32636577"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285565,"rs_event_id":1537}" data-post-hash="RxFJM48cKV2Dg"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=1537&video_id=285565&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/RxFJM48cKV2Dg">23:33.8</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 1</td><td><a href="meet/169180/results/699588">NCAA DI West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_32818087"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>4 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285876,"rs_event_id":6833}" data-post-hash="4qFrLgqSZRved"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=6833&video_id=285876&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/4qFrLgqSZRved">30:32.6<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 15</td><td><a href="meet/169828/results/701874">NCAA DI Mountain Region Cross Country Championships</a></td></tr><tr id="rID_32900812"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/81F6OdrfoYRAW">30:40.0</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 23</td><td><a href="meet/163371/results/702485">81st Men and 39th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2018_T-20690" class="card mb-2 L8 season S2018 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2018820690 = !season_2018820690"><h5 class="mb-0">2018 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Freshman</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2018820690" aria-expanded="true" aria-hidden="false"><h5>7,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_25818234"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>2 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/RxFJaaaiKV2Dg">20:56.5</a><a rel="nofollow" href="/post/RxFJaaaiKV2Dg"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 15</td><td><a href="meet/148576/results/631216">BYU Autumn Classic</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_28221198"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/QWF43jDIdAP3Q">23:24.7</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 1</td><td><a href="meet/155586/results/648821">West Coast Conference Cross Country Championships</a></td></tr><tr id="rID_27605940"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>4 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/81F60DmIoYRAW">23:55.5</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 13</td><td><a href="meet/154540/results/644132">Wisconsin D1 Pre-Nationals Cross Country Invitational</a></td></tr><tr id="rID_28217650"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":254904,"rs_event_id":1537}" data-post-hash="2qFLYAqhpDJra"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=1537&video_id=254904&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/2qFLYAqhpDJra">23:24.7<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 27</td><td><a href="meet/155588/results/648823">West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>5 Miles</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_26673639"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>5 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/MDFZxzqhAaW80">23:52.4</a><a rel="nofollow" href="/post/MDFZxzqhAaW80"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 28</td><td><a href="meet/153446/results/638331">Joe Piane Notre Dame Invitational</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_28457661"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>6 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/kVFJBpBc0QBeg">29:24.8</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 9</td><td><a href="meet/156280/results/651590">2018 NCAA Mountain Region Championships</a></td></tr><tr id="rID_28563504"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>10 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":255725,"rs_event_id":509}" data-post-hash="4qFrgpAIZRved"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=509&video_id=255725&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/4qFrgpAIZRved">29:17.1<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 17</td><td><a href="meet/146541/results/613370">80th Men and 38th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div></div>'''



soup = BeautifulSoup(html)


for s in soup.select('.card-header'):
    print(s.h5.contents[0].strip())
    for h in s.next_sibling.select('h5'):
        print(h.text)
        print('\n'.join([d.contents[0].text for d in h.find_next('table').select('tr td:nth-of-type(2) a[href^="/result"]')]))
输出
2021 Season
7,500 Meters
22:17.5
8,000 Meters
23:53.9
22:47.0
23:01.0
10,000 Meters
29:39.6
28:33.1
2020 Season
8,000 Meters
23:31.4
22:50.4
22:54.4
10,000 Meters
29:26.1
2019 Season
7,000 Meters
21:12.3
8,000 Meters
23:24.7
23:20.8
23:33.8
10,000 Meters
30:32.6
30:40.0
2018 Season
7,000 Meters
20:56.5
8,000 Meters
23:24.7
23:55.5
23:24.7
5 Miles
23:52.4
10,000 Meters
29:24.8
29:17.1

Try to give some more context in your questions so everybody could reproduce.

You could iterate the tree this way:

for s in soup.select('.card-header'):
        print(s.h5.contents[0].strip())
        for h in s.next_sibling.select('h5'):
            print(h.text)
            print('\n'.join([d.contents[0].text for d in h.find_next('table').select('tr td:nth-of-type(2) a[href^="/result"]')]))

Example

from bs4 import BeautifulSoup

html = '''
<div class="col-md-7 pull-md-5 col-xl-8 pull-xl-4 col-print-7 athleteResults" style="opacity: 1;"><div id="L-8_S-2021_T-20690" class="card mb-2 L8 season S2021 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2021820690 = !season_2021820690"><h5 class="mb-0">2021 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Senior</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2021820690" aria-expanded="true" aria-hidden="false"><h5>7,500 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_36969714"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/LnFzlVrCzKmEv">22:17.5</a><a rel="nofollow" href="/post/LnFzlVrCzKmEv"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 11</td><td><a href="meet/195402/results/801243">BYU Autumn Classic</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_37502372"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/4qF1MZgUZRved">23:53.9</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Sep 24</td><td><a href="meet/194819/results/806803">Roy Griak Invitational</a></td></tr><tr id="rID_38679433"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/QWFD2xQIdAP3Q">22:47.0</a><a rel="nofollow" href="/post/QWFD2xQIdAP3Q"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 15</td><td><a href="meet/203719/results/816808">FSU XC Invitational - Pre Nationals</a></td></tr><tr id="rID_39326032"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/PlFOnRdFMkN5j">23:01.0</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 29</td><td><a href="meet/204844/results/822145">West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_39712525"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/3DFAZDjIlPyXa">29:39.6</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 12</td><td><a href="meet/205635/results/824631">NCAA D1 Mountain Region Cross Country Championships</a></td></tr><tr id="rID_39832686"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/5rFejLxI2Ojno">28:33.1</a><a rel="nofollow" href="/post/5rFejLxI2Ojno"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 20</td><td><a href="meet/196029/results/824641">83rd Men and 41st Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2020_T-20690" class="card mb-2 L8 season S2020 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2020820690 = !season_2020820690"><h5 class="mb-0">2020 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Junior</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2020820690" aria-expanded="true" aria-hidden="false"><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_35093603"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>2 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/e2FnQpBHO8y6L">23:31.4</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 17</td><td><a href="meet/184368/results/750877">Oklahoma State Cross Country Invitational</a></td></tr><tr id="rID_35720033"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/5rFevEQH2Ojno">22:50.4<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Feb 1</td><td><a href="meet/187760/results/761386">Silver State Collegiate Challenge</a></td></tr><tr id="rID_35799610"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/rOFnro3Um6y4q">22:54.4</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Feb 24</td><td><a href="meet/189538/results/767107">West Coast Conference XC Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_35897316"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/1QFJjegTJXlQR">29:26.1<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Mar 15</td><td><a href="meet/188617/results/764003">82nd Men and 40th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2019_T-20690" class="card mb-2 L8 season S2019 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2019820690 = !season_2019820690"><h5 class="mb-0">2019 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Sophomore</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2019820690" aria-expanded="true" aria-hidden="false"><h5>7,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_29776114"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":284461,"rs_event_id":9037}" data-post-hash="KAFXwLVSeWvXQ"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=9037&video_id=284461&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/KAFXwLVSeWvXQ">21:12.3<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 14</td><td><a href="meet/160930/results/680741">BYU Autumn Classic @ East Bay Golf Course</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_30714552"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":284717,"rs_event_id":18}" data-post-hash="wyF5XNVTR3zdl"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=18&video_id=284717&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/wyF5XNVTR3zdl">23:24.7</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Sep 28</td><td><a href="meet/166197/results/686167">Bill Dellinger Invitational</a></td></tr><tr id="rID_32084024"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285208,"rs_event_id":473}" data-post-hash="xoFlBxOca6oQE"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=473&video_id=285208&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/xoFlBxOca6oQE">23:20.8<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 19</td><td><a href="meet/163418/results/695857">NCAA DI Pre-National Championships</a></td></tr><tr id="rID_32636577"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>1 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285565,"rs_event_id":1537}" data-post-hash="RxFJM48cKV2Dg"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=1537&video_id=285565&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/RxFJM48cKV2Dg">23:33.8</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 1</td><td><a href="meet/169180/results/699588">NCAA DI West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_32818087"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>4 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":285876,"rs_event_id":6833}" data-post-hash="4qFrLgqSZRved"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=6833&video_id=285876&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/4qFrLgqSZRved">30:32.6<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 15</td><td><a href="meet/169828/results/701874">NCAA DI Mountain Region Cross Country Championships</a></td></tr><tr id="rID_32900812"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/81F6OdrfoYRAW">30:40.0</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 23</td><td><a href="meet/163371/results/702485">81st Men and 39th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div><div id="L-8_S-2018_T-20690" class="card mb-2 L8 season S2018 T20690"><div class="card-header py-3 px-2 pointer" ng-click="season_2018820690 = !season_2018820690"><h5 class="mb-0">2018 Season 
<br class="hidden-lg-up"><small><a ng-click="$event.stopPropagation();" href="School.aspx?SchoolID=20690"><b>BYU Collegiate</b></a><span class="float-right" style="margin-top:4px;">College Freshman</span></small></h5></div><div class="card-block px-2 pt-2 pb-0 collapse in" uib-collapse="season_2018820690" aria-expanded="true" aria-hidden="false"><h5>7,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_25818234"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>2 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/RxFJaaaiKV2Dg">20:56.5</a><a rel="nofollow" href="/post/RxFJaaaiKV2Dg"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 15</td><td><a href="meet/148576/results/631216">BYU Autumn Classic</a></td></tr></tbody></table><h5>8,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_28221198"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/QWF43jDIdAP3Q">23:24.7</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 1</td><td><a href="meet/155586/results/648821">West Coast Conference Cross Country Championships</a></td></tr><tr id="rID_27605940"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>4 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/81F60DmIoYRAW">23:55.5</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Oct 13</td><td><a href="meet/154540/results/644132">Wisconsin D1 Pre-Nationals Cross Country Invitational</a></td></tr><tr id="rID_28217650"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>3 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":254904,"rs_event_id":1537}" data-post-hash="2qFLYAqhpDJra"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=1537&video_id=254904&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/2qFLYAqhpDJra">23:24.7<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Oct 27</td><td><a href="meet/155588/results/648823">West Coast Conference Cross Country Championships</a></td></tr></tbody></table><h5>5 Miles</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_26673639"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>5 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/MDFZxzqhAaW80">23:52.4</a><a rel="nofollow" href="/post/MDFZxzqhAaW80"><small class="text-muted pr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Personal Record">PR</small></a></td><td class="text-nowrap" style="width: 60px;">Sep 28</td><td><a href="meet/153446/results/638331">Joe Piane Notre Dame Invitational</a></td></tr></tbody></table><h5>10,000 Meters</h5><table class="table table-sm table-responsive table-hover"><tbody><tr id="rID_28457661"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>6 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1"><i class="far fa-fw"></i></span><span style="padding-left:20px"></span><a href="/result/kVFJBpBc0QBeg">29:24.8</a><span style="padding-left:20px"></span></td><td class="text-nowrap" style="width: 60px;">Nov 9</td><td><a href="meet/156280/results/651590">2018 NCAA Mountain Region Championships</a></td></tr><tr id="rID_28563504"><td class="text-nowrap" style="width:35px;"><!-- ngIf: appC.params.edit=='mark' && appC.params.canEdit --><i>10 </i></td><td class="text-nowrap" style="width: 105px;"><span class="mRight5 m-1" data-result-media-count-json="{"rs_video_id":255725,"rs_event_id":509}" data-post-hash="4qFrgpAIZRved"><span class="text-nowrap hidden-print">
<a class="has-video" target="_blank" href="http://www.runnerspace.com/eprofile.php?do=videos&event_id=509&video_id=255725&utm_source=athleticdotnet&utm_medium=videothumb&utm_campaign=athleticdotnetbios"><img src="http://www.athletic.net/images/Icons/video16h.png"></a></span></span><span style="padding-left:20px"></span><a href="/result/4qFrgpAIZRved">29:17.1<small class="text-muted sr-text" style="font-weight:normal; margin-left: 4px;" uib-tooltip="Season Record">SR</small></a></td><td class="text-nowrap" style="width: 60px;">Nov 17</td><td><a href="meet/146541/results/613370">80th Men and 38th Women NCAA DI Cross Country Championships</a></td></tr></tbody></table></div></div></div>'''



soup = BeautifulSoup(html)


for s in soup.select('.card-header'):
    print(s.h5.contents[0].strip())
    for h in s.next_sibling.select('h5'):
        print(h.text)
        print('\n'.join([d.contents[0].text for d in h.find_next('table').select('tr td:nth-of-type(2) a[href^="/result"]')]))
Output
2021 Season
7,500 Meters
22:17.5
8,000 Meters
23:53.9
22:47.0
23:01.0
10,000 Meters
29:39.6
28:33.1
2020 Season
8,000 Meters
23:31.4
22:50.4
22:54.4
10,000 Meters
29:26.1
2019 Season
7,000 Meters
21:12.3
8,000 Meters
23:24.7
23:20.8
23:33.8
10,000 Meters
30:32.6
30:40.0
2018 Season
7,000 Meters
20:56.5
8,000 Meters
23:24.7
23:55.5
23:24.7
5 Miles
23:52.4
10,000 Meters
29:24.8
29:17.1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文