-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
29 lines (21 loc) · 781 Bytes
/
utils.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
import ssl
import requests
from bs4 import BeautifulSoup
def urljoin(*args):
"""
Joins given arguments into an url. Trailing but not leading slashes are
stripped for each argument.
"""
return "/".join(map(lambda x: str(x.lstrip('/')).rstrip('/'), args))
class Soup(object):
def __call__(self, *args, **kwargs):
_url = kwargs.get('url')
# print('Requesting url: %s' % _url)
# Ignora error de certificado SSL
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
# html = urllib.request.urlopen(_url, context=ctx).read()
html = requests.get(_url)
# print(f'Requested url: {_url}')
return BeautifulSoup(html.content, 'html.parser')