练习008-009
2016-05-06 15:04
477 查看
第 0008 题:一个HTML文件,找出里面的正文。
第 0009 题:一个HTML文件,找出里面的链接。
使用的BeautifulSoup来完成的,只需要调用方法就可以,比较方便
程序如下:
感兴趣的可以看看这个文档
BeautifulSoup4.2.0文档
( 写于2016年5月6日,http://blog.csdn.net/bzd_111)
第 0009 题:一个HTML文件,找出里面的链接。
使用的BeautifulSoup来完成的,只需要调用方法就可以,比较方便
程序如下:
#!/usr/bin python #coding:utf-8 from bs4 import BeautifulSoup html=''' <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> ''' soup = BeautifulSoup(html) print soup.get_text() for i in soup.findAll('a'): print i.get('href')
感兴趣的可以看看这个文档
BeautifulSoup4.2.0文档
( 写于2016年5月6日,http://blog.csdn.net/bzd_111)
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法