-1

私はPythonが初めてです。BeautifulSoup と lxml を一緒に使用するには?

Beautifulsoup Web サイトのパーサーとして 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 に答える