下面的代码使用scray+scrapy splash+Python。
我试图从这个站点提取即将到来的比赛(包括:球队名称、锦标赛名称、开始时间):https://www.hltv.org/matches
我在回调'parse'函数中的代码是:match_days = response.xpath("//div[@class = 'upcoming-matches']//div[@class = 'match-day']")
for match in match_days.xpath("./a"):
print(match.extract())
# tournament_name = match.xpath(".//td[@class='event']//span[@class='event-name']/text()").extract_first()
# team1_name = match.xpath(".//td[@class='team-cell'][1]//div[@class='team']/text()").extract_first()
它应该为我获取每个“<;a>;”元素的内容(即应该看起来像这样,例如:
但我只对每个“<;a>;”得到这个: