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

Scrapy提取同class下两段特定文本的技术咨询

Scrapy提取目标strong文本的解决方法

方法一:获取所有strong文本后筛选

你之前用get()只会返回第一个匹配到的文本,所以拿到了'Secteur'。改用getall()就能获取所有<strong>标签里的内容:

all_strong_text = response.css('div.card-body p.card-text strong::text').getall()
# 假设目标文本是列表里的第2、3项(跳过第一个'Secteur')
fintech_text = all_strong_text[1]
serie_c_text = all_strong_text[2]

方法二:精准定位目标strong标签

如果知道目标<strong>在对应层级里的位置,用:nth-of-type直接定位:

  • 提取Fintech, Cybersecurity:
response.css('div.card-body p.card-text strong:nth-of-type(2)::text').get()
  • 提取Serie C:
response.css('div.card-body p.card-text strong:nth-of-type(3)::text').get()

方法三:先定位对应段落再取strong

如果目标文本分别在不同的p.card-text段落里,先定位段落再提取strong:
比如假设Fintech, Cybersecurity在第2个p.card-text里:

response.css('div.card-body p.card-text:nth-child(2) strong::text').get()

Serie C在第3个p.card-text里:

response.css('div.card-body p.card-text:nth-child(3) strong::text').get()

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 22:52:02