I have a program which parse HTML content to get a script src attribute and script attribute. A function have directory (contain HTML files) as input and extract to other directory as output.
However, I think my code is not clean. The following is my code.
def extract_int_js(src, dst):
for file in os.listdir(src):
filepath = os.path.join(src, file)
with open(filepath) as f:
html = f.read()
parser = HtmlParser(html)
for text in parser.script_text:
yield text
def extract_src_js(src, dst):
for file in os.listdir(src):
filepath = os.path.join(src, file)
with open(filepath) as f:
html = f.read()
parser = HtmlParser(html)
for src in parser.src:
yield src
Do you have any solution to improve this code since there are duplicated line in 2 functions.