Beautiful Soup问题汇总
2015-11-25 22:45
225 查看
# -*- coding: utf-8 -*- # requirements import requests, termcolor, html2text import os, urllib2 try: from bs4 import BeautifulSoup except: import BeautifulSoup html1 =""" <div class="zm-item-answer-author-info"><span class="name">匿名用户</span></div> """ html2=""" <div class="zm-item-answer-author-info"> <span class="name">匿名用户</span> </div> """ soup1 = BeautifulSoup(html1) print soup1.find_all("div", class_="zm-item-answer-author-info")[0].string # 匿名用户 print soup1.find_all("div", class_="zm-item-answer-author-info")[0].text # 匿名用户 soup2 = BeautifulSoup(html2) print soup2.find_all("div", class_="zm-item-answer-author-info")[0].string # None print soup2.find_all("div", class_="zm-item-answer-author-info")[0].text.strip() # 匿名用户
相关文章推荐
- 面向对象的特征和要素
- 课程设计之第二次冲刺----第三天
- 数组
- 继承、初始化方法、便利构造器
- apt-get update报错问题
- 王学岗属性动画上(十一)——属性动画的综合应用
- 制作S3C6410 的交叉编译链
- 查找OGG trail file中是否存在相关记录的命令
- Button事件实现方法的总结
- Kamailio安装指南
- Unsafe in Java
- MongoDB Days 2015 深圳 PPT 共享(干货)!
- Unix网络编程---第三次作业
- 办公软件套装 MSDN Office 2016 专业增强版
- POJ 1182 食物链 (并查集,坑题,好题)
- 安卓的几种延迟方式
- 最近做的一个安卓项目,里面有些比较实用的代码,整理一下,以备今后使用
- Kamailio 的 SIP服务器使用经验
- Pyserial+PyQT+Python3.4串口工具——界面
- 40 For which two situations would you use functionality provided by the Resource Manager? (Choose tw