首页 > 编程语言 > 详细

python html parse

时间:2015-01-09 14:03:36      阅读:403      评论:0      收藏:0      [点我收藏+]
  1. bs4:转换成unicode编码,http://www.crummy.com/software/BeautifulSoup/
    1. from bs4 import BeautifulSoup
      
      soup = BeautifulSoup(open("index.html"))
      
      soup = BeautifulSoup("<html>data</html>")
    2. Beautiful Soup将复杂HTML文档转换成一个复杂的树形结构,每个节点都是Python对象,所有对象可以归纳为4种: Tag , NavigableString ,BeautifulSoup , Comment .
    3. from bs4 import SoupStrainer
      
      only_a_tags = SoupStrainer("a")
      
      only_tags_with_id_link2 = SoupStrainer(id="link2")
      
      def is_short_string(string):
          return len(string) < 10
      
      only_short_strings = SoupStrainer(text=is_short_string)
    4. BeautifulSoup(html_doc, "html.parser", parse_only=only_a_tags)
  2. lxml: python 对 libxml 的包装
  3. html5lib:纯python实现

python html parse

原文:http://www.cnblogs.com/dmdj/p/4213103.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!