python for android : BeautifulSoup 有 bug
来源:互联网 发布:网上值机软件 编辑:程序博客网 时间:2024/05/15 04:09
BeautifulSoup 善于网页数据分析 ,但是 python for android : BeautifulSoup 有 bug ,
text = h4.a.text 只能取得 None,因此我写了function: getText() 来fix this bug.
例如: 抓取CSDN极客头条内容 soup.py
import urllib2, refrom BeautifulSoup import BeautifulSoupimport sysreload(sys)sys.setdefaultencoding('utf-8')def getText(text): begin = text.find('>',0) if begin > -1: begin += 1 end = text.find('</a>',begin) if begin < end: return text[begin:end].strip() else: return None else: return Nonepage = urllib2.urlopen("http://geek.csdn.net/new")soup = BeautifulSoup(page)for h4 in soup.findAll('h4'): if h4.a is not None: href = h4.a.get('href') text = getText(str(h4.a)) print text print hrefpage.close()
请参考: http://www.crummy.com/software/BeautifulSoup/bs3/documentation.zh.html
0 0
- python for android : BeautifulSoup 有 bug
- python for android : BeautifulSoup + ListView
- import BeautifulSoup for Python
- Python + Requests + BeautifulSoup每日BUG汇总
- python beautifulsoup
- Python BeautifulSoup
- Python BeautifulSoup
- python BeautifulSoup 安装
- python BeautifulSoup 安装
- Python BeautifulSoup 简单笔记
- python BeautifulSoup的安装
- 安装python BeautifulSoup插件
- python 中使用BeautifulSoup
- python中的BeautifulSoup模块
- Python BeautifulSoup 简单笔记
- python 中BeautifulSoup入门
- Python 安装 BeautifulSoup(Win7)
- python中用beautifulSoup 安装
- Java String with Constant pool, heap&stack
- Hadoop 2.x的DistributedCache无法工作的问题
- bencode.BTL.BTFailure: invalid bencoded value (data after valid prefix)
- 我能坚持多久-5月3日
- Java之GUI编程(二)——布局管理器
- python for android : BeautifulSoup 有 bug
- 【DataStructure&AlgorithmInJava】Ch02-PersonArrayDemo
- C++ 链表实现
- JSTL 表达式与 EL 语言
- java常用正则表达式
- R文本情感分析(3)
- linux内存释放
- 开启Android程序时检测网络与GPS是否打开
- Java中IO流知识点总结