python3X中当直接print(item)是没问题,使用item.string处理HTML网页数据输出none

from bs4 import BeautifulSoup
soup = BeautifulSoup('''<div class="short-content">
                        其实我没有看过这本书.   恰好看电视转台, 看到龙永图和杨澜在做节目, 杨澜介绍了这本书.  书的大意是(转杨澜的概述): 如果你真的想要得到什么, 或达到什么目标, 你就一定会得到: 1.因为你自觉不自觉在人生的各个路口都会选择离你设定目标最近的那种选择; 2.因为你的强烈的欲望...
                         (<a class="unfold" href="javascript:;" id="toggle-1476587-copy" title="展开">展开</a>)
                    </div>''', 'lxml')
pattern = soup.find_all('div', 'short-content')
for item in pattern:
    print(item.string)

猜你喜欢

转载自blog.csdn.net/weixin_40954495/article/details/79777345