简单、快速、现代的 Web 抓取库
h1 = soup.find('h1')
print(h1)
#
Soup
使用 attrs 参数来隔离包含特定 HTML 元素属性的标签:
soup.find('div', attrs={'class': 'section-'})默认情况下,元素属性会进行部分匹配。若要关闭此功能,请将 partial 设置为 False:
soup.find('div', {'class': 'soup'}, partial=False)重写模式参数 {'auto', 'first', 'all'} 以保证返回行为:
print(soup.find('span', mode='first'))
#
len(soup.find('span', mode='all'))
# 8Soup 对象具有 html,tag,attrs 和 text 属性:
dir(h1)
# ['attrs', 'find', 'get', 'html', 'strip', 'tag', 'text']请相应地使用它们:
print(h1.html)
# '
汤
'
print(h1.tag)
# h1
print(h1.attrs)
[parse(book) for book in books]暂无开放 Issues,或尚未同步最近议题。