css - python爬虫如何提取br标签

查看:1003
本文介绍了css - python爬虫如何提取br标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

python爬虫怎么提取br标签上面的内容呢?也就是提取行业中位数,支付宝这部分内容,由于本人只学了一点html的皮毛,还没有遇到过这种br半标签的,不知道该怎么做了,我已经试了直接用copy标签的xpath,不论定位到哪里都不行。感谢回复!

<div style="position: absolute; display: none; border-style: solid; white-space: nowrap; z-index: 9999999; transition: left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(50, 50, 50, 0.7); border-width: 0px; border-color: rgb(51, 51, 51); border-radius: 4px; color: rgb(255, 255, 255); font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 14px; font-family: &quot;Microsoft YaHei&quot;; line-height: 21px; padding: 5px; left: 620.518px; top: 173.333px;">
    20170712
    <br>
    行业中位数:35,326
    <br>
    支付宝:4
    <br>
</div>

解决方案

from pyquery import PyQuery as Q

html = '''
<div style="position: absolute; display: none; border-style: solid; white-space: nowrap; z-index: 9999999; transition: left 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.23, 1, 0.32, 1); background-color: rgba(50, 50, 50, 0.7); border-width: 0px; border-color: rgb(51, 51, 51); border-radius: 4px; color: rgb(255, 255, 255); font-style: normal; font-variant: normal; font-weight: normal; font-stretch: normal; font-size: 14px; font-family: &quot;Microsoft YaHei&quot;; line-height: 21px; padding: 5px; left: 620.518px; top: 173.333px;">
    20170712
    <br>
    行业中位数:35,326
    <br>
    支付宝:4
    <br>
</div>
'''
print Q(html).text()

这篇关于css - python爬虫如何提取br标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆