从CSS选择器中提取带有粗体内容的文本 [英] Extract text with bold content from css selector
本文介绍了从CSS选择器中提取带有粗体内容的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从论坛帖子中提取文本,但是粗体元素将被忽略.
I am trying to extract a text from forum posts, however the bold element is ignored.
如何提取像Some text to extract bold content?
这样的原始数据,目前我只得到Some text to extract ?
How can I extract raw data like Some text to extract bold content?
Currently I am getting only Some text to extract ?
<blockquote class="messageText SelectQuoteContainer ugc baseHtml">
Some text to extract <b>bold content</b>?
</blockquote>
def parse_page(self, response):
for quote in response.css('article'):
yield {
'text': quote.css('blockquote::text').extract()
}
推荐答案
使用*
选择器选择元素内所有内部元素的文本.
Use *
selector to select text of all inner elements inside an element.
''.join([ a.strip() for a in quote.css('blockquote *::text').extract() ])
这篇关于从CSS选择器中提取带有粗体内容的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文