Every line of 'read html file in python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
6 def process_html(file_name): 7 result = [] 8 with open(file_name) as f: 9 content = f.readlines() 10 lines = [] 11 for i, line in enumerate(content): 12 cur_line = line.strip() 13 if cur_line == '': 14 lines.append(' \n') 15 lines.append(' \n') 16 lines.append(' \n') 17 lines.append(' \n') 18 elif cur_line == '': 19 lines.append(' \n') 20 # lines.append(' \n') 21 lines.append(' \n') 22 lines.append(' \n') 23 # lines.append(' \n') 24 # lines.append(' \n') 25 lines.append(' \n') 26 lines.append(' \n') 27 lines.append(' \n') 28 else: 29 if cur_line == '<div>': 30 if content[i + 1].find('Table Of Contents') != -1: 31 content[i + 1] = '<h3>Contents</h3>\n' 32 if cur_line == '<h3>This Page</h3>': 33 for j in range(6): 34 content[i + j - 1] = '' 35 if cur_line.find('$('#searchbox').show(0);''': 36 # content[i] = ''; 37 lines.append(content[i]) 38 for line in lines: 39 if line: 40 result.append(line) 41 with open(file_name, 'w') as f: 42 f.write(''.join(result))</div>
453 def read_python_source(file): 454 with open(file, 'rb') as fd: 455 data = fd.read() 456 if PY3: 457 data = decode_source(data) 458 return data
25 def to_html(filename): 26 try: 27 with open(filename) as f: 28 content = f.read() 29 # TODO charset detect 30 if hasattr(content, 'decode'): 31 content = content.decode('utf-8') 32 content = publish_string(writer_name='html', source=content) 33 return content 34 except IOError as e: 35 logging.error(e.strerror) 36 raise e
12 def loadpage(filename): 13 h=open(filename,'r') 14 xml=fromstring(h.read()) 15 h.close() 16 return xml