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)
Python爬虫:如何创建BeautifulSoup对象
最新推荐文章于 2024-09-12 09:11:48 发布