cranberry-task / web_scrap.py
thunder-007's picture
Create web_scrap.py
6eb8bc2
raw
history blame contribute delete
471 Bytes
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)