我正在尝试从这个html中提取内容:
<div class=product_detail>
<p>
Random stuff
</p>
<p>
<span class="brand_color">Brand:</span>Product Brand
</p>
</div>
我可以通过response.css('span.brand_color::text')
获得“Brand:“,但无法获得“Product Brand”。
我想建立的东西:
- find the brand_color span --〉这在所有情况下都不存在
1.上去,去找父亲
1.然后往下走,以某种方式忽略跨度,然后选择::文本。
(my但是逻辑可能完全扭曲)。
多谢了!
1条答案
按热度按时间jtjikinw1#
我建议使用BeautifulSoup,它是一个非常强大的解析库。
阅读更多关于BeautifulSoup的信息,请访问:https://beautiful-soup-4.readthedocs.io/en/latest/
您可以轻松地安装它:
pip install beautifulsoup4
您将获得以下内容:
然后,您可以使用
split
提取数据