【发布时间】:2021-10-10 04:54:39
【问题描述】:
我希望使用 Scrapy 从以下 HTML 代码中提取类别和标题:
<div class="box-text box-text-products">
<div class="title-wrapper">
<p class="category uppercase is-smaller no-text-overflow product-cat op-7">Supplements </p>
<p class="name product-title"><a href="https://martslu.com/product/explosive-energy-pre-workout-cherry-punch-300g/">Explosive Energy Pre Workout Cherry Punch – 300g</a></p></div><div class="price-wrapper">
</div>
</div>
以下是我写的代码
def parse(self,response):
for product in response.css('div.box-text.box-text-products::text'):
yield{
'category': product.css('div.title-wrapper.p::text').get(),
'title': product.css('div.title-wrapper>p.name product-title::text').get()}
我仍然不清楚如何在 p 标签中指出特定的类名。任何帮助表示赞赏。
【问题讨论】:
-
提供的信息不足,
div.box-text在您提供的 html 中不存在。 -
已更新,请查收。
标签: python scrapy css-selectors