Css 用于标记之间的文本元素的Python Scrapy选择器
我需要用Python Scrapy编写一个选择器 我想得到%的CBD和%的THCCss 用于标记之间的文本元素的Python Scrapy选择器,css,python-3.x,scrapy,Css,Python 3.x,Scrapy,我需要用Python Scrapy编写一个选择器 我想得到%的CBD和%的THC test=productResponse .css('.woocmerce-product-details_uushort-description>p')[1] .get() 当我尝试这样做时,我得到的结果是: <p> <strong>CBD:</strong> 7.5%<br> <strong>THC:</strong>&
test=productResponse
.css('.woocmerce-product-details_uushort-description>p')[1]
.get()
当我尝试这样做时,我得到的结果是:
<p>
<strong>CBD:</strong> 7.5%<br>
<strong>THC:</strong><0.2%<br>
<strong>Waga:</strong> 1 gram
</p>
结果:
7.5%
如何从强文本值和第二文本值中获取值?这里不需要类。我强烈建议切换到XPath:
cbd = response.xpath('//strong[.="CBD:"]/following-sibling::text()[1]').get()
thc = response.xpath('//strong[.="THC:"]/following-sibling::text()[1]').get()
你不需要在这里上课。我强烈建议切换到XPath:
cbd = response.xpath('//strong[.="CBD:"]/following-sibling::text()[1]').get()
thc = response.xpath('//strong[.="THC:"]/following-sibling::text()[1]').get()
这回答了你的问题吗@伊洛姆斯,对不起,但这不能解决我的问题。我对不排除类的标记有问题。这能回答你的问题吗@伊洛姆斯,对不起,但这不能解决我的问题。我对标记有问题,而不是排除类。