def save_public_figure_page(self,type,p_f_name):
glovar.date = time.strftime("%Y%m%d", time.localtime())
p_f_page_file_directory = os.path.join("dataset", "html",type,glovar.date,p_f_name)
data_storage.directory_create(p_f_page_file_directory)
html_user_page = glovar.webdriver_browser.page_source
p_f_page_file = os.path.join(p_f_page_file_directory,type + "_" + p_f_name + ".html")
html_file = open(p_f_page_file, "w", encoding='utf-8')
html_file.write(html_user_page)
html_file.close()
data_storage中的directory_create函数是:
#create the file storage directory
def directory_create(path):
directory = os.path.join(os.path.dirname(__file__),path)
if not os.path.exists(directory):
os.makedirs(directory)
错误:
<class 'FileNotFoundError'> at /public_figure_name_sub
[Errno 2] No such file or directory: 'dataset\\html\\public_figure\\20170404\\Donald Trump \\public_figure_Donald Trump .html'
当前目录在/ dataset /下,我找到了目录:
F:\MyDocument\F\My Document\Training\Python\PyCharmProject\FaceBookCrawl\dataset\html\public_figure\20170404\Donald Trump
已正确创建,但文件 - public_figure_Donald Trump .html无法正确创建,请您告诉我原因以及如何更正
答案 0 :(得分:0)
正如Jean-FrançoisFabre所说,你的文件在“.html”之前有一个空格。
要解决此问题,请在第7行的变量trim()
中使用p_f_name
:
# Added trim() to p_f_name
p_f_page_file = os.path.join(p_f_page_file_directory,type +
"_" + p_f_name.trim() + ".html")
这将创建文件:
public_figure_Donald Trump.html
而不是
public_figure_Donald Trump .html
PD:无论如何,你的文件名在唐纳德和特朗普之间有很多空格。我不知道文件名的来源,但您可能想要修复它。
答案 1 :(得分:0)
bst speak
$ bst proxy lambda src/index.js
$ bst speak hello