To extract the links from the HTML using BeautifulSoup, you can use the following code:\n\npython\nfrom bs4 import BeautifulSoup\n\nhtml = '''\n<div class="contest_list">\n <table id="contest_table" class="table table-condensed table-bordered">\n <thead>\n <tr>\n <th align="center">Contest ID</th>\n <th>Title</th>\n <th>Mode</th>\n <th>Start Time</th>\n <th>Submit Time</th>\n <th>End Time</th>\n <th>Status</th>\n <th>Register</th>\n </tr>\n </thead>\n <tbody>\n <tr class="pinned">\n <td>3946</td>\n <td class="title"><a href="#contest/home/3946">���ɳ־û��߶���&�����ʷ�ר�⡿ 2023.07.14</a></td>\n <td><span class="label label-info">OI Traditional</span></td>\n <td>2023-07-12 20:46:00</td>\n <td>2023-07-11 23:46:00</td>\n <td>2023-07-11 01:46:00</td>\n <td><span class="label label-success">Ended</span></td>\n <td></td>\n </tr>\n <tr class="pinned">\n <td>3941</td>\n <td class="title"><a href="#contest/home/3941">��CDQר�⡿2023.07.10</a></td>\n <td><span class="label label-info">OI Traditional</span></td>\n <td>2023-07-10 18:43:00</td>\n <td>2023-07-10 17:43:00</td>\n <td>2023-07-10 17:43:00</td>\n <td><span class="label label-success">Ended</span></td>\n <td></td>\n </tr>\n <!-- More rows here -->\n </tbody>\n </table>\n <!-- Pagination and other elements here -->\n</div>\n'''\n\nsoup = BeautifulSoup(html, 'html.parser')\nlinks = soup.find_all('a', href=True)\n\nfor link in links:\n href = link['href']\n print(href)\n\n\nThis 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.

BeautifulSoup 获取 f'<a href={day}.+' 的链接" title="BeautifulSoup 获取 f'{day}.+' 的链接" loading="lazy">

原文地址: https://www.cveoy.top/t/topic/qhL3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录