python - output unable to write output in txt file -


steps:

  • read multiple .html files in directory
  • extract titles of html

need: - sending titles individual .txt files

expected: advise. ideally wanted extract integers html files name ('23434.html') , name text files '23434.txt'

results: - there no txt file created in designated path. - nothing gets written

for file_name in glob.glob(os.path.join(dir_path, "*.html")):     open(file_name) html_file:         soup=beautifulsoup(html_file)         d=soup.title.get_text()          #resultfile=re.findall('\d+', file_name)      open("m"+".txt", "w") outfile:         outfile.write(d)          outfile.close 

for fpath in glob.glob(os.path.join(dir_path, "*.html")):     open(fpath) html_file:         soup = beautifulsoup(html_file)         html_title = soup.title.get_text()         html_number = os.path.basename(fpath).rsplit('.',1)[0]          open(html_number + '.txt', 'w') outfile:             outfile.write(html_title) 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -