python - 仅获取网站中的一列
问题描述
我怎样才能只得到这个网站的“用户”栏? 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)
解决方案
可能你有
- 从表中查找所有行
- 然后找到标签,在您的情况下,用户位于第 5 位,因此请检查,仅此而已,这是代码示例
从 bs4 导入 BeautifulSoup 导入 urllib.request url = "https://datarecovery.com/rd/default-passwords/" 汤 = BeautifulSoup(urllib.request.urlopen(url), 'html.parser') table = soup.find('table') 对于 table.find_all('tr') 中的 tr: all_text = [] ct = 0 对于 tr 中的 td: ct += 1 文本 = td.get_text(strip=True) 如果 ct == 5: 打印(文本) #输出为:用户 # 根 #技术 # SNMP写入 # (没有任何) # (没有任何) # DOCSIS_APP # 行政
推荐阅读
- azure - Azure SQL 数据库和 SQL Server PAAS - 为什么两者都需要?
- vue.js - vue 单元测试与 jest
- ios - 单击tableview行后如何导航到另一个视图
- sql - IBM DB2:具有多个连接的 SQL 查询
- android - 在颤振中使用地理编码器包时出错
- node.js - “assets”文件夹中的 Sails.JS 部分加载问题
- angular - 角度打印功能未显示输入内的文本和角度材料样式
- c++ - C++17 Using Class Template Argument Deduction 用于保存函数返回值的类型的指南
- ssh - libgit2sharp-ssh 与代理一起工作?
- bluetooth - UWP蓝牙查找设备耗时较长