crawl-mufti-pahang / scraper.py
Ammar-Azman's picture
Upload 2 files
d2da8eb
from xtractor.utils import extractor, read_the_json, dumps_the_json, jsonl_converter
def get_article(link):
soup = extractor(link)
divtag = soup.find_all("div", class_="elementor-toggle-item")
title = []
for divtitle in divtag:
title_div = divtitle.find("a", class_="elementor-toggle-title")
title.append(title_div.text)
article = []
for divTag in divtag:
text = str(divTag.text).replace("\n", " ").strip()
article.append(text)
return title, article
if __name__ == "__main__":
all_title = []
all_body = []
for i in range(14, 23):
try:
data = get_article(
f"https://mufti.pahang.gov.my/index.php/keputusan-fatwa-20{i}/"
)
all_title.append(data[0])
all_body.append(data[1])
except:
pass
flat_title = [y for x in all_title for y in x]
flat_body = [y for x in all_body for y in x]
data_dict = {"title": flat_title, "body": flat_body}
dumps_the_json(data_dict, json_file_name="./mufti_pahang/mufti_pahang_artikel.json")
jsonl_converter(
json_file_path="./mufti_pahang/mufti_pahang_artikel.json",
json_l_file_path="./mufti_pahang/mufti_pahang_artikel.jsonl",
col_1_name="title",
col_2_name="body",
)