Scrapy css 选择器:获取所有内部标签的文本 [英] Scrapy css selector: get text of all inner tags

查看:33
本文介绍了Scrapy css 选择器:获取所有内部标签的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标签,我想让里面的所有文本都可用.我正在这样做:

I have a tag and I want to get all the text inside available. I am doing this:

response.css('mytag::text')

但它只是获取当前标签的文本,我也想从所有内部标签中获取文本.

But it is only getting the text of the current tag, I also want to get the text from all the inner tags.

我知道我可以这样做:

response.xpath('//mytag//text()')

但我想用 css 选择器来做.我怎样才能做到这一点?

But I would like to do it with css selectors. How can I achieve this?

推荐答案

response.css('mytag *::text')

* 将访问 mytag 的所有内部标签,::text 将获取每个标签的文本

The * will visit all the inner tags of mytag and ::text will get the text of each of them

这篇关于Scrapy css 选择器:获取所有内部标签的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆