赞
踩
- from urllib import request
- from bs4 import BeautifulSoup
-
- headers = {
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3894.0 Safari/537.36"
- }
-
- req = request.Request("https://blog.csdn.net/wtl1992",headers=headers)
-
- connection = request.urlopen(req)
-
- html = connection.read().decode("utf-8")
-
- document = BeautifulSoup(html,features="lxml")
-
- print(document.select_one("div.avatar-box.d-flex.justify-content-center.flex-column"))
- print(document.select("div.avatar-box.d-flex.justify-content-center.flex-column"))
-
document.select : 选择器选择匹配的所有内容
document.select_one:选择器选择匹配的第一个
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。