我是Python的新手。如何一起使用BeautifulSoup和lxml?
中使用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()
答案 0 :(得分:2)
在调用BeautifulSoup()
构造函数时指定解析器:
import urllib2
from bs4 import BeautifulSoup
soup = BeautifulSoup(urllib2.urlopen("http://www.google.com").read(), "lxml")