beautifulsoup获取fa href=#contesthomed+day+alink href=csstablewithpincss rel=stylesheetdiv class=contest_listtable id=contest_table class=table table-condensed table-borderedtheadtrth align=centerContes
To extract the links from the HTML using BeautifulSoup, you can use the following code:
from bs4 import BeautifulSoup
html = '''
<div class="contest_list">
<table id="contest_table" class="table table-condensed table-bordered">
<thead>
<tr>
<th align="center">Contest ID</th>
<th>Title</th>
<th>Mode</th>
<th>Start Time</th>
<th>Submit Time</th>
<th>End Time</th>
<th>Status</th>
<th>Register</th>
</tr>
</thead>
<tbody>
<tr class="pinned">
<td>3946</td>
<td class="title"><a href="#contest/home/3946">���ɳ־û��߶���&�����ʷ�ר�⡿ 2023.07.14</a></td>
<td><span class="label label-info">OI Traditional</span></td>
<td>2023-07-12 20:46:00</td>
<td>2023-07-11 23:46:00</td>
<td>2023-07-11 01:46:00</td>
<td><span class="label label-success">Ended</span></td>
<td></td>
</tr>
<tr class="pinned">
<td>3941</td>
<td class="title"><a href="#contest/home/3941">��CDQר�⡿2023.07.10</a></td>
<td><span class="label label-info">OI Traditional</span></td>
<td>2023-07-10 18:43:00</td>
<td>2023-07-10 17:43:00</td>
<td>2023-07-10 17:43:00</td>
<td><span class="label label-success">Ended</span></td>
<td></td>
</tr>
<!-- More rows here -->
</tbody>
</table>
<!-- Pagination and other elements here -->
</div>
'''
soup = BeautifulSoup(html, 'html.parser')
links = soup.find_all('a', href=True)
for link in links:
href = link['href']
print(href)
This code will find all <a> tags with an href attribute and print out their values. In this example, it will extract the links #contest/home/3946 and #contest/home/3941. You can modify the code to suit your specific needs
原文地址: https://www.cveoy.top/t/topic/iAQU 著作权归作者所有。请勿转载和采集!