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- ...
随机推荐
- 小白逛公园加强版(park)
小白逛公园加强版(park) 题目描述 小新经常陪小白去公园玩,也就是所谓的遛狗啦--在小新家附近有n个公园,这些公园通过一些路径相连,并保证每两个公园之间有且仅有一条通路相连(也就是说这是一棵树), ...
- MFC点击控件拖动窗口
void CMouseClickDlg::OnLButtonDown(UINT nFlags, CPoint point) { CDialogEx::OnLButtonDown(nFlags, poi ...
- Xcode 真机调试报错:This application's application-identifier entitleme
This application's application-identifier entitlement does not match that of the installed appli ...
- codechef AUG17 T4 Palindromic Game
Palindromic Game Problem Code: PALINGAM There are two players A, B playing a game. Player A has a st ...
- JavaScript-性能优化,函数节流(throttle)与函数去抖(debounce)
我在写一个类似百度搜索框的自动提示功能时候,使用了AJAX+keydown事件.调试时候我发现,当在搜索框中输入文字的时候,控制台在不停发送AJAX.这在本地服务器测试还好,如果我把它拿到运行环境,很 ...
- LeetCode OJ-- Length of Last Word
https://oj.leetcode.com/problems/length-of-last-word/ 对一个字符串遍历,求最后一个单词的长度,如果有 ‘ ’,则切开了. 字符串的最后一个字符为 ...
- With语句在数据统计应用
WITH TMP_EXECUTOR(EXECUTOR,EXECUTORNAME) AS ( SELECT DISTINCT T.EXECUTOR ,T1.FULLNAME AS EXECUTORNAM ...
- PHP中的stristr(),strstr(),strpos()速度比较
测速代码: <?php function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); ret ...
- 8大排序算法的java实现--做个人收藏
排序算法分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因为数据量太大,一次不能容纳全部的排序记录,在排序过程中需要访问外存.这里只讨论内部排序,常见的内部排序算法有:插入排序 ...
- UVA 10976 Fractions Again?!【暴力枚举/注意推导下/分子分母分开保存】
[题意]:给你一个数k,求所有使得1/k = 1/x + 1/y成立的x≥y的整数对. [分析]:枚举所有在区间[k+1, 2k]上的 y 即可,当 1/k - 1/y 的结果分子为1即为一组解. [ ...