采集数据的html解析方法
通过爬虫请求url一般会获取html数据,需要快捷进行文档解析,定位获取元素数据。 Beautiful Soup 能够从HTML或XML文件中提取数据的Python库.可以通过转换器实现惯用的文档导航,查找,修改文档的方法。Beautiful Soup会极大的提高文档分析效率,减少研发的投入时间。下面将展示BeautifulSoup4中所有主要特性,表明它适合做什么,如何工作和使用,并到达想要的效果和处理异常情况. html_doc = """ <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