Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from bs4 import BeautifulSoup
- import json
- def read_html(path):
- tank = []
- c=0
- indexes = []
- htmls = []
- files = os.listdir(path)
- for file in files:
- if file.endswith("html") or file.endswith("htm"):
- htmls.append(file)
- with open(htmls[0]) as f:
- container = f.read()
- soup = BeautifulSoup(container, "html.parser")
- paras = soup.findAll("p", {"align":"JUSTIFY"})
- content = str(paras)
- target = content.split("\n")
- for i, item in enumerate(target):
- if "Sol" in item:
- indexes.append(int(i))
- for i, item in enumerate(indexes):
- current = i
- next = i+1
- try:
- tank.append(target[indexes[current]:indexes[next]])
- except IndexError:
- pass
- tank = [str(item).replace('p align="JUSTIFY"', "br").replace(",", " ").replace('<p align="CENTER"', "").replace("[", "").replace("]", "").replace("</p>", "") for item in tank]
- print(tank)
Advertisement
Add Comment
Please, Sign In to add comment