Spaces:
Sleeping
Sleeping
import requests | |
from bs4 import BeautifulSoup | |
url = 'https://www.cranberry.fit/post/ovulation-pain-unmasking-the-mystery' | |
response = requests.get(url) | |
try: | |
soup = BeautifulSoup(response.content, 'html.parser') | |
article_content = soup.find('article') | |
if article_content: | |
article_text = article_content.get_text(separator='\n', strip=True) | |
with open('blog.txt', 'w') as f: | |
f.write(article_text) | |
except Exception as e: | |
print(e) | |