darknet_diaries_llm/download_transcripts.py

29 lines
810 B
Python
Raw Normal View History

2023-10-06 21:35:53 +02:00
import requests
2023-10-07 00:30:46 +02:00
import os
2023-10-06 21:35:53 +02:00
from bs4 import BeautifulSoup
2023-10-07 00:30:46 +02:00
folder_path = "transcripts"
if not os.path.exists(folder_path):
os.makedirs(folder_path)
2023-10-06 21:35:53 +02:00
for i in range(1, 139):
url = f"https://darknetdiaries.com/transcript/{i}"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
2023-10-07 00:57:45 +02:00
transcript = soup.find('pre').get_text()
title_section = soup.find('h1').get_text()
url = f"https://darknetdiaries.com/episode/{i}"
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
downloads = soup.find(id='downloads').get_text()
ep, title = title_section.split(":", 1)
ep = ep.strip()
title = title.strip()
with open(f"{folder_path}/episode_{i}.txt", "w") as f:
f.write(f"{title}\n{downloads}\n{transcript}")
print(f"{ep} {title}")