-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_name.py
36 lines (27 loc) · 958 Bytes
/
get_name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import subprocess
import re
from bs4 import BeautifulSoup
from check_folder import check_and_create_folder
def send_curl_request(url):
try:
output = subprocess.check_output(['curl', url], stderr=subprocess.STDOUT)
return output.decode('utf-8')
except subprocess.CalledProcessError as e:
return None
def extract_meta_tags(response):
soup = BeautifulSoup(response, 'html.parser')
# Extract the meta tags
title = soup.find('meta', property='og:title')
type_ = soup.find('meta', property='og:type')
return {
'title': title['content'] if title else "No title found.",
'type': type_['content'] if type_ else "No type found."
}
def name(url):
response = send_curl_request(url)
if response:
meta_tags = extract_meta_tags(response)
name = meta_tags['title']
type_ = meta_tags['type']
check_and_create_folder(name)
return name