Pythonクローラー:BeautifulSoupオブジェクトを作成する方法

from urllib.request import urlopen
from bs4 import BeautifulSoup

html = '<div>text1</div>'
html = urlopen("http://www.pythonscraping.com/pages/page3.html")
html = open('c:\\aa.html')

#以上三行表示了HTML的三种来源,一是字符串形式,二是在线网页形式,三是HTML文件形式

bsObj = BeautifulSoup(html, 'html.parser') # 'html.parser'是解析器,也可以用'lxml'
# BeautifulSoup类似于C++中的构造函数
e = bsObj.find('div')
print(e.text)

おすすめ

転載: blog.csdn.net/xtingjie/article/details/73442317