将html转换为txt,Python 将HTML转换为TXT

CODE:

#!/usr/bin/python

# -*- coding: utf-8 -*-

'''

Created on 2014-9-5

@author: guaguastd

@name: html_to_text.py

'''

from login import google_api_request

from html import cleanHtml

while True:

query = raw_input("Input query(None to quit): ")

if query.strip() == '':

break

#people_feed = google_login_http("people", "query", query)

#people_feed = google_api.people().search(query=query).execute()

#print json.dumps(people_feed['items'], indent=1)

people_feed = google_api_request(0, action='search', query=query)

for user in people_feed['items']:

userId = user['id']

activity_feed = google_api_request(1, action='list', collection='public', maxResults='100', userId=userId)

#print json.dumps(activity_feed, indent=1)

print '\nPrimary content including HTML tag:'

print activity_feed['items'][0]['object']['content']

print '\nConverted content without HTML tag:'

print cleanHtml(activity_feed['items'][0]['object']['content'])

RESULT:

Input query(None to quit): Tim O'Reilly

Primary content including HTML tag:

ABC World News covers @HomeDepot credit card data breach, recommends @BillGuard to protect yourself! BillGuard on ABC World News Tonight With David Muir … (Minute 1:25)

Converted content without HTML tag:

ABC World News covers @HomeDepot credit card data breach, recommends @BillGuard to protect yourself! BillGuard on ABC World News Tonight With David Muir … (Minute 1:25 )

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值