root@xxxx:~# pip install bs4 DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',))': /simple/bs4/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',))': /simple/bs4/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',))': /simple/bs4/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',))': /simple/bs4/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', error('Tunnel connection failed: 403 Forbidden',))': /simple/bs4/ ERROR: Could not find a version that satisfies the requirement bs4 (from versions: none) ERROR: No matching distribution found for bs4
#Python2安装 apt-get install -y python-bs4 #Python3安装 apt-get install -y python3-bs4
html_doc = """ <html><head><title>The Dormouse's story</title></head> <body> <p class="title"><b>The Dormouse's story</b></p> <p class="story">Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie" class="sister" id="link1">Elsie</a>, <a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and <a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>; and they lived at the bottom of a well.</p> <p class="story">...</p> """
2)打印
from bs4 import BeautifulSoup soup = BeautifulSoup(html_doc, 'html.parser') print(soup.prettify())
会输出一段格式好的段落
apt-cache search package #搜索包 apt-cache show package #获取包的相关信息,如说明、大小、版本等 apt-get install package #安装包 apt-get install package --reinstall #重新安装包 apt-get -f install #强制安装 apt-get remove package #删除包 apt-get remove package - - purge #删除包,包括删除配置文件等 apt-get autoremove #自动删除不需要的包 apt-get update #更新源 apt-get upgrade #更新已安装的包 apt-get dist-upgrade #升级系统 apt-get dselect-upgrade #使用 dselect 升级 apt-cache depends package #了解使用依赖 apt-cache rdepends package #了解某个具体的依赖 apt-get build-dep package #安装相关的编译环境 apt-get source package #下载该包的源代码 apt-get clean && sudo apt-get autoclean #清理下载文件的存档 apt-get check #检查是否有损坏的依赖
官网:https://beautifulsoup.readthedocs.io/zh_CN/v4.4.0/
李先生(Lemon),高级运维工程师(自称),SRE专家(目标)。喜欢钻研底层技术,认为底层基础才是王道。一切新技术都离不开操作系统(CPU、内存、磁盘)、网络等。坚持输入输出,记录自己学习的点滴,在平凡中坚持前行,总有一天会遇见不一样的自己。公众号:运维汪(ID:Leeeee_Li)。