請問python 表格爬蟲有辦法將轉出的csv檔存到py檔當前路徑,並將csv檔名改為html檔所在資料夾名稱嗎?目前只能做出爬當前路徑下html檔
以下是我的程式碼:
import pandas as pd
import os
directoryPath = r"./"
os.chdir(directoryPath)
folderLister = os.listdir(directoryPath)
for folders, sub_folders, file in os.walk(directoryPath):
for name in file:
if name.endswith(".html"):
filename=os.path.join(folders,name)
print(filename)
print(name)
dfs = pd.read_html(filename)
html_filename = filename.replace('.html', '.csv')
dfs[3].to_csv(html_filename)