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

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

问题描述

我有一个标签,我想让所有可用的文本都可用。我这样做:

  response.css('mytag :: text')

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



我知道我可以这样做:

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

但是我想用 css selectors

解决方案

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

* 会访问所有 mytag :: text 的内部标签都会得到每个标签的文本


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.

I know I could do something like:

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

but I would like to do it with css selectors

解决方案

response.css('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天全站免登陆