python - 如何在python中一一划分值?
问题描述
import requests
import json
from bs4 import BeautifulSoup
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'}
url = 'https://olympics.com/tokyo-2020/olympic-games/ko/results/all-sports/medal-standings.htm'
res = requests.get(url, headers = headers)
soup = BeautifulSoup(res.content, 'html.parser')
data = soup.select('td.text-center')
for item in data:
text = item.get_text().replace(' ', '')
print(text)
我正在爬东京奥运会奖牌榜,我怎样才能改变这个像数组(或列表)?
解决方案
添加text
到 alist
并打印。
在这里,我添加text
到res
列表并打印它。
res = []
for item in data:
text = item.get_text().strip().replace(' ', '')
res.append(text)
# printing the res list
print(res)
推荐阅读
- amazon-cognito - 在一段时间不活动后自动禁用已确认的 AWS Cognito 用户账户
- c# - 根据工作日安排 Azure Function
- amazon-web-services - AWS - Boto -第一次服务后停止服务
- c# - 如何创建只能输入数字的文本框?
- android - libwebviewchromium.so 在 AndroidTV 上崩溃,没有错误消息或堆栈跟踪
- python - 如何查询以便显示模型的字段而不是实际模型
- android - 如何将 Firebase 实时数据库与 RxJava 结合使用
- cordova - 如何在我的 ionic 应用程序中安装本机运行包?
- tensorflow - 我可以从具有动态大小的 TensorArray 中删除特定元素吗?
- pdf - 如何在高内存的 VBS 中运行命令