我怎样才能只得到这个网站的“用户”栏? https://datarecovery.com/rd/default-passwords/
我试着做:
from bs4 import BeautifulSoup
import urllib.request
url = "https://datarecovery.com/rd/default-passwords/"
soup = BeautifulSoup(urllib.request.urlopen(url))
for tag in soup.find_all("span", "paraEight"):
tag = str(tag)
print (tag)
但是我意识到每列都有“paraEight”类值,所以我得到了每列的所有值
更新:
soup = BeautifulSoup(urllib.request.urlopen(url))
for tag in soup.select(".table-responsive table tr td:nth-of-type(5) span"):
tag = str(tag)
print (tag)
我不确定beautifulsoup是否支持CSS selector的全部功能,但您能否尝试使用selector查找元素:
.table-responsive table tr td:nth-of-type(5) span
我在你链接的页面上尝试了这个方法,它给出了用户列的所有包含用户数据的跨度(例如“root”、“tech”等)
也许你有
尝试使用lxml模块和xpath。我想差不多了
相关问题 更多 >
编程相关推荐