编辑:这是我尝试使用的代码:
from bs4 import BeautifulSoup
import re
import sys
m = re.compile("^\d\d:\d\d$")
readfile = open("C:\\Temp\\LearnPythonTheCompletePythonProgrammingCourse_Udemy.htm", 'r').read()
soup = BeautifulSoup(readfile, "html.parser")
ci_details = soup.findAll("span",{"class":"ci-details"})
timeList = []
for detail in ci_details:
for span in detail.findAll("span"):
if m.match(span.text):
timeList.append(span.text)
print (timeList)
for i in timeList:
time1=timeList[0]
print(time1)
编辑我意识到这一点,我告诉Python为timeList中的每个项目打印time1。如何迭代timeList?
我想使用dstubeda的代码获取列表中的每个条目,将其转换为原始秒,然后添加它们。一旦完成,我会将它们转换为h:m:s。我的for循环在哪里出错?