1 # -*-coding:utf-8-*-
2 __author__ = 'Deen'
3 '''
4 题目描述:
5 一个HTML文件,找出里面的正文。
6
7 思路:
8 利用BeautifulSoup或者正则表达式
9
10 '''
11 '''
12 import requests
13 from bs4 import BeautifulSoup
14
15
16 def get_body(url):
17 response = requests.get(url)
18 soup = BeautifulSoup(response)
19 print soup.body.text
20 '''
21 from bs4 import BeautifulSoup
22
23 def find_the_content(path):
24 with open(path) as f:
25 text = BeautifulSoup(f, 'lxml')
26 content = text.get_text().strip('\n')
27
28 return content.encode('gbk','ignore')
29
30
31 if __name__ == '__main__':
32 print find_the_content('Show-Me-the-Code_show-me-the-code_1.html')

python练习册 每天一个小程序 第0008题的更多相关文章

  1. python练习册 每天一个小程序 第0013题

    # -*-coding:utf-8-*- ''' 题目描述: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-) 地址: http://tieba.baidu.com/p/21 ...

  2. python练习册 每天一个小程序 第0001题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生 ...

  3. python练习册 每天一个小程序 第0007题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 有个目录,里面是你自己写过的程序,统计一下你写过多少行代码.包括空行和注释,但 ...

  4. python练习册 每天一个小程序 第0000题

    PIL库学习链接:http://blog.csdn.net/column/details/pythonpil.html?&page=1 1 #-*-coding:utf-8-*- 2 __au ...

  5. python练习册 每天一个小程序 第0010题

    # -*-coding:utf-8-*- ''' 题目描述: 使用 Python 生成类似于下图中的字母验证码图片 思路: 运用PIL库加random 随机字母进行生成 ''' import rand ...

  6. python练习册 每天一个小程序 第0009题

    1 ''' 2 题目描述: 3 找出一个html文件中所有的url 4 5 思路 : 6 利用正则表达式进行匹配 7 8 ''' 9 10 11 import re 12 13 14 with ope ...

  7. python练习册 每天一个小程序 第0006题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目描述: 5 你有一个目录,放了你一个月的日记,都是 txt,为了避免分词的问题,假设内容都 ...

  8. python练习册 每天一个小程序 第0005题

    1 # -*-coding:utf-8-*- 2 __author__ = 'Deen' 3 ''' 4 题目说明: 你有一个目录,装了很多照片,把它们的尺寸变成都不大于 iPhone5 分辨率的大小 ...

  9. python练习册 每天一个小程序 第0012题

    # -*-coding:utf-8-*- def test(content): text = content flag = 0 with open('filtered_words.txt') as f ...

随机推荐

  1. Solution -「CF 1586F」Defender of Childhood Dreams

    \(\mathcal{Description}\)   Link.   定义有向图 \(G=(V,E)\),\(|V|=n\),\(\lang u,v\rang \in E \Leftrightarr ...

  2. Solution -「AGC 016F」Games on DAG

    \(\mathcal{Description}\)   Link.   给定一个含 \(n\) 个点 \(m\) 条边的 DAG,有两枚初始在 1 号点和 2 号点的棋子.两人博弈,轮流移动其中一枚棋 ...

  3. Solution -「LOCAL」模板

    \(\mathcal{Description}\)   OurOJ.   给定一棵 \(n\) 个结点树,\(1\) 为根,每个 \(u\) 结点有容量 \(k_u\).\(m\) 次操作,每次操作 ...

  4. HashMap(1.8)源码学习

    一.HashMap介绍 1.哈希表(hash table) 在哈希表中进行添加,删除,查找等操作,时间复杂度为O(1) 存储位置 = f(关键字) 其中,这个函数f一般称为哈希函数,这个函数的设计好坏 ...

  5. Centos下Ambari2.7.5的编译和安装

    前言 终于,要开始写点大数据相关的文章了.当真的要开始写老本行的时候,还是考虑了挺久的.一是不知道从何处写起,二是如何能写点有意思的. 我们常说,过程比结果重要.也是有很多人喜欢准备完全之后,才会开始 ...

  6. 我的平安夜-Merry Christmas

    我的平安夜-Merry Christmas 平安夜给自己买的第一个"苹果",嘻嘻. 今夜,不想去学习技术知识点什么的, 我们就想到哪里写哪里,就简单聊聊思维方式吧. 其实我不想做今 ...

  7. 云原生 PostgreSQL 集群 - PGO:来自 Crunchy Data 的 Postgres Operator

    使用 PGO 在 Kubernetes 上运行 Cloud Native PostgreSQL:来自 Crunchy Data 的 Postgres Operator! Cloud Native Po ...

  8. Spring Boot 自定义配置文件异常"expected single matching bean but found 2"

    运行环境:Spring Boot 2.5.0, IDEA 2020.3.2 异常详细信息: Injection of resource dependencies failed; nested exce ...

  9. NSSCTF-no_wakeup

    打开网页是一个派萌的表情包(原神玩家手动狗头) 按照题目的提示点击,出现题目的源码, 观察题目源码,发现就是一个简单的反序列化,这边手打一下php (自己太菜了,枯了) <?phpclass H ...

  10. python https 无法访问 SSLError("Can\'t connect to HTTPS URL because the SSL module is not available

    1,需要检查python 安装的时候是否支持 https 进入python 环境,import ssl 如果正常导入就可以使用https,不能导入就需要进入下一步. 2,查看系统是否安装了openss ...