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- ...
随机推荐
- 游戏(bzoj 1854)
Description lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性 ...
- POJ1385 Lifting the Stone
There are many secret openings in the floor which are covered by a big heavy stone. When the stone i ...
- Java中Collections的sort方法和Comparable与Comparator的比较
一.Comparable 新建Student1类,类实现Comparable接口,并重写compareTo方法 public class Student1 implements Comparable& ...
- 从数据库的表导出到Excel表格中【让客户端下载的Excel】
原文发布时间为:2008-10-11 -- 来源于本人的百度文章 [由搬家工具导入] 这个例子是从gridview中导出到Excel,可以举一反三,可以直接从数据库中取值放在DataSet中,然后再从 ...
- C语言中的内存相关问题
内存是用来存储数据与程序的,对我们写程序来说非常重要.所以内存对程序来说几乎是本质需求.越简单的程序需要越少的内存,而越庞大越复杂的程序需要更多的内存. 注意:在嵌入式系统中有ROM和RAM两类内存, ...
- mybatis hashmap 输入键值对为空时,key 丢失
参考文档:https://blog.csdn.net/lulidaitian/article/details/70941769 springMVC+mybatis查询数据,返回resultType=” ...
- LeetCode OJ-- 3Sum Closest
https://oj.leetcode.com/problems/3sum-closest/ 给一列数和target,在这一列数中找出3个数,使其和最接近target,返回这个target. 一般思路 ...
- AC日记——幸运号码 51nod 1043
幸运号码 思路: 传说中的数位dp: 不难发现,n(n<1000) ,那么,n个数的最大和为9*1000=9000: 对于9000*1000的时间范围,我们可以用dp来解决: dp[i][j], ...
- 2018年东北农业大学春季校赛 I wyh的物品【01分数规划/二分】
链接:https://www.nowcoder.com/acm/contest/93/I来源:牛客网 题目描述 wyh学长现在手里有n个物品,这n个物品的重量和价值都告诉你,然后现在让你从中选取k个, ...
- POJ 2057 The Lost House [树状DP]
题意:一只蜗牛将壳忘在了一棵树的某一个末结点(叶子)上.它想找回自己的壳,但忘记是丢在哪个结点上了,只好从树根开始网上爬,一个结点一个结点地找.在一些结点上居住着毛毛虫,它们会告诉蜗牛该结点以及它的子 ...