>>> from bs4 import BeautifulSoup #导入
>>> soup = BeautifulSoup(url.content,"lxml")
>>> print(soup.prettify) #Formatting cost
>>> print(soup.title.string)
Zhengzhou Institute of Light Industry OJ #Print title
>>> print(soup.title)
<title>OJ of Zhengzhou Institute of Light Industry</title>
Tag selector:
>>> print(soup.a)
<a class="navbar-brand" href="./" style="font-weight:bold;">Zhengzhou Institute of Light Industry OJ</a>
>> print(soup.title.name)
title
Take zuli's zcm network as the grabbing object:
>>> print(soup.div.attrs['class'])
['container']
>>> print(soup.nav.attrs['class'])
['navbar', 'navbar-default']
>>> print(soup.nav.attrs['role'])
navigation
(You can use this method to get the corresponding content after the label)
The rest of the writing:
>>> print(soup.nav['role'])
navigation