在选择没有html标签的子元素的XPath时遇到麻烦,我需要选择所有没有html标签的元素。
没有任何html标记的子元素看起来像this。
答案 0 :(得分:0)
假设要选择“ 64”值(在图片中),请使用:
选择器对象的 response.xpath('//div[@class="spaceit"/text()')
,如果要返回值,请在行末添加.get()
或.getall()
。 More info here
当然,我无法确定整个HTML的结果,因为类div
可能有多个spaceit
标签。
我也想加强@Roman的评论,并希望将来您在问题中提供Minimal Reproducible Examples。
答案 1 :(得分:0)
要完成@renatodvc的答案,请使用3个选项从MAL中提取FMAB的发作次数:
response.xpath('normalize-space(//span[.="Episodes:"]/following::text()[1])')
response.xpath('normalize-space(//span[.="Episodes:"]/../text()[normalize-space()])')
response.xpath('normalize-space(//div[@class="spaceit"][./span[.="Episodes:"]]/text()[normalize-space()])')
这3种情况下的输出:64