mnemlaghi commited on
Commit
f4ce1df
1 Parent(s): b3f3132
Files changed (1) hide show
  1. utils.py +14 -0
utils.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from bs4 import BeautifulSoup
2
+ import requests
3
+ import string
4
+
5
+ def get_image_from_url(url):
6
+ try:
7
+ r = requests.get(url)
8
+ soup = BeautifulSoup(r.content, 'html.parser')
9
+ img = soup.find('figure', 'thumbnail').find('img')
10
+ return img['src']
11
+ except:
12
+ return None
13
+
14
+ depunctuate = lambda x: x.translate(str.maketrans('','',string.punctuation))