-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparsear_facil.py
24 lines (21 loc) · 1.02 KB
/
parsear_facil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def main():
"""
Main function to parse a local HTML file and extract content
from <li> tags.
It reads the HTML content line by line, checks for lines
that start with '<li>' and end with '</li>', and prints
the content within those tags.
"""
with open('web_scraping/web.html', mode='r') as file:
goal_init = '<li>' # Starting tag to look for
goal_end = '</li>' # Ending tag to look for
for line in file.readlines():
# Check if the line starts with the opening <li> tag and ends with the closing </li> tag
if line.strip().startswith(goal_init) and line.strip().endswith(goal_end):
# Print the content between the tags, stripping the tags from the line
print(line.strip().replace(goal_init, '').replace(goal_end, ''))
if __name__ == '__main__':
try:
main() # Execute the main function when the script runs
except KeyboardInterrupt:
exit() # Exit the program gracefully on keyboard interrupt