You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Python网络爬虫中应用表格类选择器筛选目标链接?

问题:限定爬虫仅抓取指定表格内的网球赛事链接

我编写的Python网络爬虫可正常运行,但会抓取到网页表格外无关的超链接。希望将筛选条件限定为仅抓取类名为table-main only12 js-nrbanner-t的表格内的相关网球赛事链接。

原代码如下:

import requests
from bs4 import BeautifulSoup
import pandas as pd

r = requests.get('https://www.betexplorer.com/results/tennis/?year=2022&month=11&day=02')
soup = BeautifulSoup(r.text, "html.parser")

matchlist = set('https://www.betexplorer.com'+a.get('href') for a in soup.select('a[href^="/tennis"]:has(strong)'))

print(pd.DataFrame(matchlist))

补充:Driftr95已找到我所需的准确解决方案,即便我当时的问题表述有误。


内容的提问来源于stack exchange,提问作者NewGuy1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 22:35:38