-1

我对 Python 很陌生。如何一起使用 BeautifulSoup 和 lxml?

Beautifulsoup 网站推荐使用 lxml 作为解析器

def get_html():

        from bs4 import BeautifulSoup
        import lxml

        soup = BeautifulSoup(open("http://www.google.com"));
        #print(soup.prettify());
        print(soup.title);

if __name__ == '__main__':
        get_html()
4

1 回答 1

2

BeautifulSoup()在调用构造函数时指定解析器:

import urllib2
from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen("http://www.google.com").read(), "lxml")
于 2012-11-20T15:59:54.173 回答