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的更多相关文章

  1. Python on Android

    Python on Android Posted on April 29, 2015 by Alexander Taylor   There are an increasing number of r ...

  2. 收藏的技术文章链接(ubuntu,python,android等)

    我的收藏 他山之石,可以攻玉 转载请注明出处:https://ahangchen.gitbooks.io/windy-afternoon/content/ 开发过程中收藏在Chrome书签栏里的技术文 ...

  3. uiautomator2 使用Python测试 Android应用

    GitHub地址:https://github.com/openatx/uiautomator2 介绍 uiautomator2 是一个可以使用Python对Android设备进行UI自动化的库.其底 ...

  4. python下载安装BeautifulSoup库

    python下载安装BeautifulSoup库 1.下载https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ 2.解压到解压 ...

  5. 【Android】让Python在Android系统上飞一会儿

    第一节 在手机上配置Python运行环境 1.下载和安装 Scripting Layer for Android (SL4A) Scripting Layer for Android (SL4A) 是 ...

  6. 转 让Python在Android系统上飞一会儿

    让Python在Android系统上飞一会儿 地址: http://blog.csdn.net/ccwwff/article/details/6208260

  7. 【Python爬虫】BeautifulSoup网页解析库

    BeautifulSoup 网页解析库 阅读目录 初识Beautiful Soup Beautiful Soup库的4种解析器 Beautiful Soup类的基本元素 基本使用 标签选择器 节点操作 ...

  8. python中的BeautifulSoup使用小结

    1.安装 pip install beautifulsoup4 2.代码文件中导入 from bs4 import BeautifulSoup 3. 解析器 使用方法 优势 劣势 Python标准库 ...

  9. Python进行Android开发步骤

    移动应用开发 1. 建立开发环境 下载软件开发包(SDK):        http://developer.android.com/sdk/index.html        adt-bundle- ...

随机推荐

  1. 【10】react 之 react-router

    1.1.  路由 路由:URL与处理器的映射. 浏览器当前的 URL 发生变化时,路由系统会做出一些响应,用来保证用户界面与 URL 的同步. 1.2.  Router安装 npm i react-r ...

  2. github的一些简单用法

     关于 项目 上传  大多数人都是使用命令行上传 步骤分为以下几步: 在github上创建你的  repositories  ->github.com - >右下角  new reopsi ...

  3. 通过Xode上传代码到GIthub---步骤

    ---恢复内容开始--- 一:打开终端,git命令进行全局配置 由于本人已经配置完成,so,直接查看配置信息 然后在本地创建一个文件夹, 然后在gitHub上创建一个代码库 在终端clone到本地创建 ...

  4. powershell 调用winform dll

    //1.加载dll,调用winform窗体,使用指定构造函数 param{ $filePath="" } [void][reflection.assembly]::LoadFile ...

  5. DOS头结构

    DOS头结构typedef struct _IMAGE_DOS_HEADER {                 // DOS .EXE header   +0h WORD   e_magic;    ...

  6. Linux 6.x 下Oracle 11g R2 安装配置

    Oracle 11g R2 数据库安装硬件配置要求: 最小内存 1 GB of RAM 虚拟内存容量,这个oracle也有要求,不用担心此时的swap分区不够oracle的要求 .虚拟内存swap如何 ...

  7. 设置jenkins的邮件通知功能

    1.进入系统配置页面配置邮件发送的SMTP 2. 进入项目配置页面,配置邮件通知:(每次不稳定构建时会邮件通知)

  8. Codeforces Gym101473 F.Triangles-前缀和 (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)

    前缀和. 代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include< ...

  9. 页面css代码

    博主原来的页面css代码 (这个是原来的那种效果,差不多弄出来会是这种效果http://www.cnblogs.com/thmyl/) /*simplememory*/ #google_ad_c1, ...

  10. iptables 一些有用的规则

      -A INPUT -i lo -j ACCEPT #允许本机内部访问,即回环 -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #允许 ...