Created
June 25, 2021 23:27
-
-
Save thepycoach/31222a652c508c5f8087fbba2876aa6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import requests | |
root = 'https://subslikescript.com' | |
website = f'{root}/movies' | |
result = requests.get(website) | |
content = result.text | |
soup = BeautifulSoup(content, 'lxml') | |
box = soup.find('article', class_='main-article') | |
links = [link['href'] for link in box.find_all('a', href=True)] | |
# print(links) # href doesn't consider root | |
for link in links: | |
result = requests.get(f'{root}/{link}') | |
content = result.text | |
soup = BeautifulSoup(content, 'lxml') | |
box = soup.find('article', class_='main-article') | |
title = box.find('h1').get_text() | |
transcript = box.find('div', class_='full-script').get_text(strip=True, separator=' ') | |
with open(f'{title}.txt', 'w') as file: | |
file.write(transcript) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment