Beautiful soup的使用方法

如何使用

  • 将一段文档传入BeautifulSoup 的构造方法,就能得到一个文档的对象, 可以传入一段字符串或一个文件句柄.
    •   from bs4 import BeautifulSoup
        soup = BeautifulSoup(open("index.html"))
        soup = BeautifulSoup("<html>data</html>")
      
    • 首先,文档被转换成Unicode,并且HTML的实例都被转换成Unicode编码
      •    	BeautifulSoup("Sacr&eacute; bleu!")
           	<html><head></head><body>Sacré bleu!</body></html>
        
    • 然后,Beautiful Soup选择最合适的解析器来解析这段文档,如果手动指定解析器那么Beautiful Soup会选择指定的解析器来解析文档.(参考 解析成XML ).
发布了51 篇原创文章 · 获赞 29 · 访问量 2388

猜你喜欢

转载自blog.csdn.net/fangweijiex/article/details/103736995
今日推荐