thunder-007 commited on
Commit
6eb8bc2
1 Parent(s): cb597f8

Create web_scrap.py

Browse files
Files changed (1) hide show
  1. web_scrap.py +16 -0
web_scrap.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+
4
+ url = 'https://www.cranberry.fit/post/ovulation-pain-unmasking-the-mystery'
5
+
6
+ response = requests.get(url)
7
+
8
+ try:
9
+ soup = BeautifulSoup(response.content, 'html.parser')
10
+ article_content = soup.find('article')
11
+ if article_content:
12
+ article_text = article_content.get_text(separator='\n', strip=True)
13
+ with open('blog.txt', 'w') as f:
14
+ f.write(article_text)
15
+ except Exception as e:
16
+ print(e)