我有一个名为25600501.html的html文件
示例文件名
-25600501.html
-25600502.html
-25600503.html
-25600504.html
-25600505.html
我想阅读一个html文件循环。
with open(r'C:/Users/bac/Desktop/WORK/PYTHON/25600501.html', "r") as f:
page = f.read()
root = LH.fromstring(page)
谢谢
答案 0 :(得分:0)
您可以尝试使用glob.iglob循环文件目录C:/Users/bac/Desktop/WORK/PYTHON/
中的所有html文件,如下所示:
import glob
for filename in glob.iglob('C:/Users/bac/Desktop/WORK/PYTHON/*.html'): #it will loop all your html files in the dir C:/Users/bac/Desktop/WORK/PYTHON/
with open(filename) as f:
page = f.read()