python for android : BeautifulSoup 有 bug
BeautifulSoup 善于网页数据分析 。可是 python for android : BeautifulSoup 有 bug ,
text = h4.a.text 仅仅能取得 None,因此我写了function: getText()
来fix this bug.
比如: 抓取CSDN极客头条内容 soup.py
import urllib2, re
from BeautifulSoup import BeautifulSoup
import sys
reload(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 None page = 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 href
page.close()
请參考: http://www.crummy.com/software/BeautifulSoup/bs3/documentation.zh.html
python for android : BeautifulSoup 有 bug的更多相关文章
- Python on Android
Python on Android Posted on April 29, 2015 by Alexander Taylor There are an increasing number of r ...
- 收藏的技术文章链接(ubuntu,python,android等)
我的收藏 他山之石,可以攻玉 转载请注明出处:https://ahangchen.gitbooks.io/windy-afternoon/content/ 开发过程中收藏在Chrome书签栏里的技术文 ...
- uiautomator2 使用Python测试 Android应用
GitHub地址:https://github.com/openatx/uiautomator2 介绍 uiautomator2 是一个可以使用Python对Android设备进行UI自动化的库.其底 ...
- python下载安装BeautifulSoup库
python下载安装BeautifulSoup库 1.下载https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ 2.解压到解压 ...
- 【Android】让Python在Android系统上飞一会儿
第一节 在手机上配置Python运行环境 1.下载和安装 Scripting Layer for Android (SL4A) Scripting Layer for Android (SL4A) 是 ...
- 转 让Python在Android系统上飞一会儿
让Python在Android系统上飞一会儿 地址: http://blog.csdn.net/ccwwff/article/details/6208260
- 【Python爬虫】BeautifulSoup网页解析库
BeautifulSoup 网页解析库 阅读目录 初识Beautiful Soup Beautiful Soup库的4种解析器 Beautiful Soup类的基本元素 基本使用 标签选择器 节点操作 ...
- python中的BeautifulSoup使用小结
1.安装 pip install beautifulsoup4 2.代码文件中导入 from bs4 import BeautifulSoup 3. 解析器 使用方法 优势 劣势 Python标准库 ...
- Python进行Android开发步骤
移动应用开发 1. 建立开发环境 下载软件开发包(SDK): http://developer.android.com/sdk/index.html adt-bundle- ...
随机推荐
- 利用ROS内建SLAM建立地图
ros中建地图方式有两种: 首先1.首先下载hector_slam包到你工作空间的src下 命令: cd ~/catkin/src git clone https://github.com/tu-da ...
- 使用PropTypes进行类型检测
PropTypes 是react提供的用于检验数据类型的typechecking,避免应用越来越大的时候出现意料之外的bug class Greeting extends React.Componen ...
- linux 下 多进程与多线程
[Linux]多进程与多线程之间的区别 http://blog.csdn.net/byrsongqq/article/details/6339240 网络编程中设计并发服务器,使用多进程与多线程 ,请 ...
- hdu 2145(迪杰斯特拉)
zz's Mysterious Present Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- js动态设置根元素的rem方案
方案需求: rem 单位在做移动端的h5开发的时候是最经常使用的单位.为解决自适应的问题,我们需要动态的给文档的根节点添加font-size 值. 使用mediaquery 可以解决这个问题,但是每一 ...
- Cryptography I 学习笔记 --- 密钥交换
1. 使用可信第三方(Trusted third parties)进行密钥交换. a. Alice与TTP之间的密钥是K1,Bob与TTP之间的密钥是K2. b. Alice向TTP发起一个与Bob交 ...
- 玲珑杯 Round #5 Problem E Tetration (枚举 + 欧拉公式)
题目链接 Tetration 题意 给定一个排列 现在可以任意调整这个排列的顺序 求$a_{1}^{a_{2}^{a_{3}^{...^{a_{n}}}}}$对$p$取模的最小值 直接枚举$a$ ...
- HDU5877 Weak Pair
题目链接 Weak Pair 题意十分明确, 就是求出符合题意的有序点对个数. 首先对ai离散,离散之后的结果用rk[i]表示,然后进行二分预处理得到f[i],其中f[i]的意义为:其他的点和i这个节 ...
- gradients的一些注意点
Each variable has a [.grad_fn] attribute that references a Function that has created the Variable(ex ...
- 在html里网页中嵌入优酷的视频
<html> <embed src="http://player.youku.com/player.php/sid/XMjAzOTk4NjI4/v.swf" qu ...